我所有的函数都有错误 C2084:函数'function'已经有一个主体
All my functions have error C2084: function 'function' already has a body
我在网站的其他地方看到过类似的重载函数和这个错误的问题,但是这发生在我所有的函数上,我不知道发生了什么或如何解决它。
我不确定这是否只是我犯了一个基本的语法错误,这是可怕的错误还是更险恶的东西。如果有人有任何想法,请帮助。
哦,我为这个问题的糟糕格式道歉,这是我问的第一个问题。
错误C2084:函数'Node::Node(Board *,int)'已经有body
node.h(16):参见前面对'{ctor}'的定义
Node.h
#pragma once
#include "Board.h"
class Node
{
private:
Board* nodeBoard;
int currentPlayer;
int value;
Node** childrenNodes;
public:
//----some constructors----
Node(Board* board, int player) {};
Node(Board* board) {};
~Node(){};
//----other functions----
Node generateChildren(int playerX, int playerY, Board* board) {}
// other functions exist in the same format
};
Node.cpp
#pragma once
#include "Node.h"
Node::Node(Board* board, int player)
{
nodeBoard = board;
currentPlayer = player;
childrenNodes = NULL;
}
Node::Node(Board* board)
{
nodeBoard = board;
}
Node::~Node(){};
Node Node::generateChildren(int playerX, int playerY, Board* board)
{
//this fills the nodes based on if the squares next to the player are moveable
}
注。Board是我制作的另一个类,它具有与Node相同的问题。
Node(Board* board, int player) {};
应该是
Node(Board* board, int player);
类定义中的。{}
是一个空的实现,这使得其他定义不合法。
与其他构造函数和方法相同。或者,您可以在类定义中保持实现内联,但随后必须从实现文件中删除它们。
从。h文件中删除空大括号-它们不属于那里。
相关文章:
- 我可以在构造函数的主体中转发构造吗?
- GCC 能否优化具有相同主体的函数的代码大小?
- 构造函数主体内的本地指针C++内存泄漏
- 调用一个小函数两次(例如在if条件和主体中)比将结果存储在局部变量中更可取
- 我可以检查初始化列表中设置的构造函数主体中的变量吗
- 如果函数是在类的主体中定义的,我是否需要在成员函数的返回类型中指定 typename?
- 重载运算符主体仅包含一个函数调用
- 具有相同主体的两个函数具有不同的名称
- 错误 C2084:函数"int main(void)"已具有主体
- 在成员初始值设定项列表和构造函数主体中委派构造函数有什么区别
- 是否可以在构造函数主体中初始化成员变量,而不是初始值设定项列表
- 构造函数主体中的简单指针语法出现问题
- 从子类的构造函数主体调用基类的构造函数
- 构造函数主体中的对象初始化
- C++样式:在构造函数主体中使用参数或成员
- 避免在 c++ 构造函数主体中赋值的任何方法
- auto_ptr构造函数主体(不在初始化器列表中)的成员初始化
- 仅在 constexpr 函数主体中的未计算上下文中使用的参数
- 构造函数主体前面的冒号是否表示继承
- C++类:是否可以在构造函数主体中选择成员的构造函数?(无需双重初始化成员)