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 回答