C++ 错误C2079:&x27;myMath';使用未定义的类';数学工具

C++ 错误C2079:&x27;myMath';使用未定义的类';数学工具,c++,C++,我有一个名为Utils.h的文件。我在里面放了一些课程。这些类的名称是:Point、Edge、Cone和mathTools。我还有另外两个名为RedBlackTree.h和RedBlackTree.cpp的文件,它们包含类RedBlackTree的声明和实现。My main()函数位于source.cpp中。我可以在其中包含Utils.h和RedBlackTree.h,而且没有问题。但当我在“RedBlackTree.h”中包含Utils.h时,我会遇到错误C2079。我听说这是因为标题中存在循

我有一个名为Utils.h的文件。我在里面放了一些课程。这些类的名称是:
Point
Edge
Cone
mathTools
。我还有另外两个名为
RedBlackTree.h
RedBlackTree.cpp
的文件,它们包含类
RedBlackTree
的声明和实现。My main()函数位于
source.cpp
中。我可以在其中包含
Utils.h
RedBlackTree.h
,而且没有问题。但当我在“RedBlackTree.h”中包含
Utils.h
时,我会遇到错误C2079。我听说这是因为标题中存在循环依赖,但我不能在这里使用它。 另一个奇怪的错误是:
错误C2370:“最大输入大小”:重新定义;不同的存储类
,如果我没有在
RedBlackTree.h
中包含
“Utils.h”
,则不会发生此错误

编辑:
如果我写
mathTools*myMath而不是
mathTools myMath
我的Utils.h如下所示:

#include <cstdlib>
#include <algorithm>
#include <string>
#include <map>

#define PI 3.14159265358979323
#define and &&
#define or ||

#define TETA 30.0f
#define OMEGA 0.15f

const int max_input_size = 50;
//const unsigned long long INF = 2147483647;
#define INF 2147483647


class Point{
public:
/*
Some Functions
*/

private:
/*
. . . 
*/
};

class Edge{
public:
// . . . 
private:
// . . . 
};

class Cone{
public:
// . . .
};

class mathTools{
public:// . . . 
private:// . . .
};
#ifndef UTILS_H
#define UTILS_H
//Utils.h codes 
#endif
#包括
#包括
#包括
#包括
#定义PI 3.14159265358979323
#定义和&&
#定义或||
#定义TETA 30.0f
#定义ω0.15f
const int max_input_size=50;
//常量无符号长INF=2147483647;
#定义INF 2147483647
类点{
公众:
/*
一些功能
*/
私人:
/*
. . . 
*/
};
阶级边缘{
公众:
// . . . 
私人:
// . . . 
};
类锥{
公众:
// . . .
};
类数学工具{
公众:/。
私人:/。
};
红黑树

#include "Utils.h" //if I comment this line, there wont be error C2097 

#pragma once

// class prototype
template <class Comparable>
class RedBlackTree;

template <class Comparable>
class RBTreeNode{
    /*
    .
    .
    .
    */
friend class RedBlackTree<Comparable>;
};

template <class Comparable>
class RedBlackTree
{
public:
    //...

private:
    //...
};
#包括“Utils.h”//如果我对这行进行注释,则不会出现错误C2097
#布拉格语一次
//类原型
模板
红木类;
模板
RBTreeNode类{
/*
.
.
.
*/
朋友级红黑树;
};
模板
类红黑树
{
公众:
//...
私人:
//...
};
source.cpp

#include "Utils.h"
#include "RedBlackTree.cpp"


//____________________GLOBAL VARIABLES
mathTools myMath; //error C2079: 'myMath' uses undefined class  'mathTools'
              // and there are lots of errors after it

std::vector<Cone>cones;
std::vector<Point>input;
std::vector<Edge> outLawEdges;

bool E[max_input_size][max_input_size] = { false };
double t_sp[max_input_size][max_input_size] = { (double)INF };
double FW[max_input_size][max_input_size] = { (double)INF };
double dist[max_input_size][max_input_size] = { (double)INF };

int main(){
// . . . 
}
#包括“Utils.h”
#包括“RedBlackTree.cpp”
//____________________全局变量
数学工具myMath//错误C2079:“myMath”使用未定义的类“mathTools”
//在这之后有很多错误
向量锥;
向量输入;
std::向量向量向量;
布尔E[max_input_size][max_input_size]={false};
双t_sp[max_input_size][max_input_size]={(double)INF};
双FW[max_input_size][max_input_size]={(double)INF};
双区[最大输入大小][最大输入大小]={(双)INF};
int main(){
// . . . 
}

> P>在C语言和C++编程语言中,一种包含保护(有时称为宏守卫)的特殊构造是用来避免在处理包含指令时双重包含的问题。在头文件中添加#include-guard是使该文件幂等的一种方法。()。更改
Utils.h
RedBlackTree.h
如下:

#include <cstdlib>
#include <algorithm>
#include <string>
#include <map>

#define PI 3.14159265358979323
#define and &&
#define or ||

#define TETA 30.0f
#define OMEGA 0.15f

const int max_input_size = 50;
//const unsigned long long INF = 2147483647;
#define INF 2147483647


class Point{
public:
/*
Some Functions
*/

private:
/*
. . . 
*/
};

class Edge{
public:
// . . . 
private:
// . . . 
};

class Cone{
public:
// . . .
};

class mathTools{
public:// . . . 
private:// . . .
};
#ifndef UTILS_H
#define UTILS_H
//Utils.h codes 
#endif


#包括“RedBlackTree.cpp”
?cpp??在所有其他包含之前移动
#pragma一次
。是否尝试按照粘贴在此处的方式编译代码,以查看是否仍然失败?如果它不尝试从原始代码添加行,直到失败并查看问题的根源。您可以使用
代替
&
|
。不要重新定义它们。@chris我正在使用MSVS 2013,如果我没有定义
它会给我:
错误C2065:“和”:未声明的标识符