こんにちは、私は c++ で小さなプロジェクトを書いています。そこでは、いくつかの作業を行ういくつかのクラスが必要です。インターフェイスとクラスの実装を作成しました。
私を驚かせたのは、main() なしでは単純なクラスを持つことができないということです. 一度インスタンス化されたクラスが欲しいです. メソッドは呼び出すことができます.クラス実装の main()。これは、私が持ちたいものの頭の中にある例です。
ファイル animal.h:
class animal
{
public:
animal();
~animal();
public:
int method1(int arg1);
private:
int var1;
};
ファイル animal.cpp:
#include "animal.h"
animal::animal(){...}
animal::~animal(){...}
int animal::method1(int arg1){return var1;}
}
そして、別のファイルから動物クラスを呼び出して、次のように動作させたいと思います: app.cpp ファイル:
#include <neededlib>
#include "animal.h"
int main()
{
animal dog;
cout << dog.method1(42);
return 0;
}
しかし、コンパイラは私に与えます
/usr/lib/gcc/i686-pc-linux-gnu/4.3.3/../../../crt1.o: In function _start:
"(.text+0x18): undefined reference to `main`"
collect2: ld returned 1 exit status
animal.cppの場合、そこにメインは必要ありませんか、それとも必要ですか?
どこが間違っていますか?