【问题标题】:No members available in C++ [duplicate]C ++中没有可用的成员[重复]
【发布时间】:2013-06-05 19:32:15
【问题描述】:
我有课
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 根本不识别这种方法。它指出
表达式必须有一个类类型
【问题讨论】:
标签:
c++
visual-studio-2010
most-vexing-parse
【解决方案1】:
你在这里声明一个函数:
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
【解决方案2】:
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.