未定义的Class :: Class()引用和函数在一个文件中? C ++

时间:2017-07-28 02:28:08

标签: c++ dependencies circular-dependency

所有内容都编写得很好,我在这里查看了大约10个不同的问题,试图解决它,包括thisthisthis。请不要杀了我,我已经在墙上撞了大约3个小时了。我也试过自己构建有问题的文件,它看起来很好,但是当我构建项目时,它仍然会抛出同样的错误。

我已经尝试将include“.h's”尽可能地移动到cpp文件中,这在大多数情况下仍然没有帮助。当我改变

Character

BitBoards *newBoard = new BitBoards;

该行上的错误消失了,但它仍然给我“未定义的参考”newBoard->功能。

我还应该尝试其他明显或不明显的事情吗?

我的逻辑文件中弹出错误:Ai_Logic.cpp

BitBoards *newBoard;

Ai_Logic.h:

 //master bitboard for turn
BitBoards *newBoard = new BitBoards;
^^here
//master zobrist object for ai turn
ZobristH *mZobrist = new ZobristH;

//master evaluation object - evaluates board position and gives an int value (- for black)
evaluateBB *mEval = new evaluateBB;

newBoard->constructBoards();
^^and here as well as every instance of newBoard-> below

Ai_Logic.cpp

#include <string>
#include <stack>
#include <thread>
class Pieces;
class ZobristH;
class BitBoards;
class MoveGen;
class evaluateBB;
class HashEntry;

class Ai_Logic
{
//stuff
};

BitBoards.h

#include "ai_logic.h"

#include <algorithm>
#include <stdlib.h>
#include <time.h>
#include <iostream>

#include "externs.h"
#include "move.h"
#include "evaluatebb.h"
#include "bitboards.h"
#include "movegen.h"
#include "zobristh.h"

BitBoards.cpp

class MoveGen;
class ZobristH;
class Move;

class BitBoards
{
//stuff
};

我认为问题可能来自我的MoveGen.h / cpp,但我不完全确定

MoveGen.h

#include "bitboards.h"
#include <cmath>
#include <random>
#include <iostream>
#include <string>
#include <cstdio>

#include "externs.h"
#include "movegen.h"    

MoveGen.cpp

#include <iostream>
#include <string>
#include "move.h"

class Pieces;
class BitBoards;
class ZobristH;


class MoveGen
{
//stuff
};

1 个答案:

答案 0 :(得分:1)

#include bitboards.cpp 

在Ai_Logic文件中似乎可以解决问题。绝对不知道为什么。