我所有的函数都有错误 C2084:函数'function'已经有一个主体

All my functions have error C2084: function 'function' already has a body

本文关键字:函数 主体 有一个 function C2084 有错误      更新时间:2023-10-16

我在网站的其他地方看到过类似的重载函数和这个错误的问题,但是这发生在我所有的函数上,我不知道发生了什么或如何解决它。

我不确定这是否只是我犯了一个基本的语法错误,这是可怕的错误还是更险恶的东西。如果有人有任何想法,请帮助。

哦,我为这个问题的糟糕格式道歉,这是我问的第一个问题。

错误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文件中删除空大括号-它们不属于那里。