0

クラスがあります

class Test{
public:
    Test(){};
    ~Test(){};
    void test() {cout<<"test"<<endl;};
};

そしてmain.cppには次のものがあります:

#include "Test.h"

using namespace std;

int main(){
     Test t();
     t.test();
}

これはメソッドを宣言する正しい方法ですか、それとも間違っていますか? VS2010 はこのメソッドをまったく認識しません。それは次のように述べています

式にはクラス型が必要です

4

2 に答える 2

2

ここで関数を宣言しています:

Test t(); // function t(), returning a Test instance

代わりにこれを試してください:

Test t;  // t is a Test instance
Test t2{}; // t2 is a Test instance, C++11 only
于 2013-06-05T19:33:32.673 に答える
0
First thing is that 
class Test{
public:
    Test(){};(Your Default Constructor when you will make the object this constructor will call)
    ~Test(){};(when you will release this object your destructor will call)
    void test() {cout<<"test"<<endl;};
};
Here you don't need to call manually.
于 2013-06-05T19:42:55.230 に答える