zum*_*uha 1 c++ pointers class
我想在类之外声明以下代码的方法,但是每当该方法是指向私有成员变量的指针时,我都会收到以下错误:“没有函数模板“std::next”的实例与所需的 typeC/C++(386 )”。
class Node
{
private:
int data;
Node *next;
public:
Node() {}
int GetData() { return data; }
Node *GetNext() { return next; }
void SetData(int aData) { data = aData; }
void SetNext(Node *aNext) { next = aNext; }
};
// outside try class declaration of
int Node::GetData() { return data; }
Node Node::*GetNext() { return next; } // here is the error!!
Run Code Online (Sandbox Code Playgroud)
你能帮我吗?
这是错误的
Node Node::*GetNext() { return next; }
Run Code Online (Sandbox Code Playgroud)
这是对的
Node* Node::GetNext() { return next; }
Run Code Online (Sandbox Code Playgroud)
函数的名称是Node::GetNext和 不是GetNext。