【发布时间】:2011-01-07 16:59:13
【问题描述】:
当函数的前向声明在源文件 (.cpp) 中起作用时,为什么对类不起作用?
谢谢。
// main.cpp
void forwardDeclaredFunction() ; // This is correct
class One ; // Why this would be wrong
int One:: statVar = 10 ;
void
One :: anyAccess() {
std::cout << "\n statVar:\t " << statVar ;
std::cout << "\n classVar:\t" << classVar ;
}
class One {
public:
void anyAccess() ;
static int statVar ;
private:
int classVar ;
} ;
int main (int argc, char * const argv[]) {
One *obj = new One ;
return 0;
}
void forwardDeclaredFunction() {
}
【问题讨论】:
-
class One;是前向类声明的正确语法。你到底得到了什么编译器错误消息? -
错误:不完整类型结构一的使用无效;我在 Mac 上运行
标签: c++ visual-c++