gpt4 book ai didi

c++ - 我所有的函数都有错误 C2084 : function 'function' already has a body

转载 作者:太空宇宙 更新时间:2023-11-04 14:42:01 26 4
gpt4 key购买 nike

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

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

哦,对于这个问题的糟糕格式,我深表歉意,这是我问的第一个问题。

error C2084: function 'Node::Node(Board *,int)' already has a body

node.h(16) : see previous definition of '{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

}

附言Board是我做的另一个类,它和Node有同样的问题。

最佳答案

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

应该是

Node(Board* board, int player); 

在类定义中。 {} 是一个空实现,它使其他定义非法。

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

关于c++ - 我所有的函数都有错误 C2084 : function 'function' already has a body,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14198799/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com