0

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

我不确定是否只是我犯了一个基本的语法错误,这个错误已经严重错误或更险恶。如果有人有任何想法,请提供帮助。

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

错误 C2084:函数 'Node::Node(Board *,int)' 已经有一个主体

node.h(16) : 参见之前对 '{ctor}' 的定义

节点.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

};

节点.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 

}

Ps Board 是我制作的另一个类,它与 Node.js 有相同的问题。

4

2 回答 2

12
Node(Board* board, int player) {};

应该是

Node(Board* board, int player); 

在类定义中。这{}是一个空的实现,这使得另一个定义是非法的。

其他构造函数和方法也是如此。或者,您可以在类定义中保持内联实现,但您必须从实现文件中删除它们。

于 2013-01-07T15:25:00.320 回答
0

从您的 .h 文件中删除空括号 - 它们不属于那里。

于 2013-01-07T15:27:36.563 回答