我正在尝试使用在包含的头文件中声明的typedef,但是出现以下错误:
error: ‘Status’ was not declared in this scope
Status status;
^
在文件中包含的标头中声明typedef。
Server.hh(简体):
class myClass {
public:
typedef mynamespace::Status Status;
...
}
ClientServer.cc:
#include "Server.hh"
...
Status status; // error thrown here
这种方法是否有问题?如何使typedef可用于多个文件?
答案 0 :(得分:0)
typedef
,using
和namespace
均位于编写该语句的代码块的本地。您必须将Server.hh
重新组织为
typedef mynamespace::Status Status;
class myClass {
public:
...
}
供Server.cc
访问,因为typedef
将位于最外面的代码块中。