Kat*_*ick 9 c++ struct compilation
我得到一个问题,而返回类型是结构
Example.h
class Example {
private:
typedef struct connection_header {
string url;
string method;
};
static connection_header get_connection_header();
};
Example.cpp
connection_header Example::get_connection_header() {
return NULL;
}
Run Code Online (Sandbox Code Playgroud)
我正进入(状态 'connection_header' does not name a type
我可以知道为什么会出现这个错误
jua*_*nza 11
您正在使用typedef
而不给该类型命名.只需放下typedef
,这里不需要:
struct connection_header {
string url;
string method;
};
Run Code Online (Sandbox Code Playgroud)
接下来,connection_header
在Example
类的内部声明,因此当它是返回类型时,您需要在实现中完全限定其名称:
Example::connection_header Example::get_connection_header()
Run Code Online (Sandbox Code Playgroud)