tre*_*son 7 c++ visual-studio-2010 visual-studio
所以我遇到了一个问题,我确信有一个非常明显的解决方案,但我似乎无法弄明白.基本上,当我尝试在我的标题中执行类定义和在我的源文件中实现时,我收到一个错误,说我正在重新定义我的类.使用Visual C++ 2010 Express.
确切错误:"错误C2011:'节点':'类'类型重新定义"
示例代码如下:
Node.h:
#ifndef NODE_H
#define NODE_H
#include <string>
class Node{
public:
Node();
Node* getLC();
Node* getRC();
private:
Node* leftChild;
Node* rightChild;
};
#endif
Run Code Online (Sandbox Code Playgroud)
Node.cpp:
#include "Node.h"
#include <string>
using namespace std;
class Node{
Node::Node(){
leftChild = NULL;
rightChild = NULL;
}
Node* Node::getLC(){
return leftChild;
}
Node* Node::getRC(){
return rightChild;
}
}
Run Code Online (Sandbox Code Playgroud)
class Node{
Node::Node(){
leftChild = NULL;
rightChild = NULL;
}
Node* Node::getLC(){
return leftChild;
}
Node* Node::getRC(){
return rightChild;
}
}
Run Code Online (Sandbox Code Playgroud)
你在代码中声明了两次类,第二次在你的.cpp文件中.为了为您的课程编写函数,您将执行以下操作
Node::Node()
{
//...
}
void Node::FunctionName(Type Params)
{
//...
}
Run Code Online (Sandbox Code Playgroud)
不需要上课
| 归档时间: |
|
| 查看次数: |
20211 次 |
| 最近记录: |