我在一个类
中嵌入一个结构时遇到错误这是头文件
class chord
{
public:
struct Node
{
void del(string, chord&);
void insert(string, chord&);
};
map<int, Node>& getNodeList(); # line 44
}
这是错误消息:
44|error: candidate is: std::map<int, chord::Node>& chord::getNodeList()|
这是.ccp文件
map<int, Node>& chord::getNodeList() # line 34
{
return Node_List;
}
当我尝试编译时,我收到以下错误
main.cpp|34|error: 'Node' was not declared in this scope
main.cpp|34|error: template argument 2 is invalid|
main.cpp|34|error: template argument 4 is invalid|
main.cpp|34|error: prototype for 'int& chord::getNodeList()' does not match any in class 'chord'|
当我更改为以下类型时,我收到此错误
|35|error: invalid use of non-static data member 'chord::node'|
|44|error: from this location|
class chord
{
public:
struct Node
{
void del(string, chord&);
void insert(string, chord&);
}node;
map<int, node>& getNodeList();
}
感谢您的帮助
答案 0 :(得分:0)
Node
在chord
内定义,因此当它在.cpp文件中看到map<int, Node>
时,它找不到Node
。把chord::
放在它前面。
map<int, chord::Node>& chord::getNodeList()
在第二个代码段中,声明一个名为Node
的{{1}}类型的成员对象,然后尝试将其用作模板类型参数。您需要第一个代码段中的语法。