IntelliSense:标识符“节点”未定义

时间:2019-10-17 15:35:11

标签: c++

我无法解决错误。标识符“ node”在.cpp文件的最后第二行中未定义。我想返回该节点,但是编译器显示错误文件,请帮助我解决该问题。

 #include<iostream>
    using namespace std;
    class Node
    {
    private:
        int data;
        Node *node;
    public:
        Node(int, Node *);
        void setdata(int);
        void setnode(Node *);
        int getdata() const;
        Node *getnode();
    };

#include<iostream>
#include"Node.h"
using namespace std;

Node::Node(int Data = 0, Node *n = NULL)
{
    setdata(Data);
    setnode(n);
}
void Node::setdata(int D)
{
    data = D;
}
void Node::setnode(Node *N)
{
    node = N;
}
int Node::getdata() const
{
    return data;
} 
Node Node::*getnode()
{
    return node;
}

1 个答案:

答案 0 :(得分:0)

class Node {
private:
  // ...
public:
  // ...
  Node *getnode();  // Returning a pointer to a Node, my guess is the * placement
                    // is confusing you
};

// Other implementations

Node* Node::getnode() // Means the same thing as above; * placement is relatively
                      // flexible
{
  return node;  // return type now matches what you're returning
}

您的函数实现编写不正确就是全部。鉴于C ++通常有多严格,放置*的灵活性可能会使初学者感到困惑。