C2061 错误:"标识符",但我包含标头?
C2061 error: 'identifier', but I included the header?
我正在做一个VC++项目(没有什么可视化的,只是使用Visual Studio进行编辑)。在我的一堂课上,我有一堆 C2061 错误,但 evreything 很好,我仔细检查了三重检查。这是发生错误的类:圆圈:
#ifndef __SGE__Circle__
#define __SGE__Circle__
#include <GLFW/glfw3.h>
#include "Vector2.h"
#include "Rectangle.h"
class Circle
{
public:
Circle();
Circle(float xCenter, float yCenter, float radius);
Circle(Vector2& center, float radius);
~Circle();
bool Contains(Vector2& point);
bool Contains(Rectangle& rectangle); //ERROR OCCURS HERE
bool Contains(Circle& circle);
bool isContained(Rectangle& rectangle); //ERROR OCCURS HERE
bool Intersects(Rectangle& rectangle); //ERROR OCCURS HERE
bool Intersects(Circle& circle);
float Radius;
Vector2 Center;
};
#endif
错误是这样的:错误 C2061:语法错误:标识符"矩形"他们到处都是矩形被称为矩形
矩形类如下所示:
矩形.h:
#ifndef __SGE__Rectangle__
#define __SGE__Rectangle__
#include <GLFW/glfw3.h>
#include "Vector2.h"
class Rectangle
{
public:
Rectangle();
Rectangle(float x, float y, float width, float height);
Rectangle(Vector2& position, Vector2& size);
~Rectangle();
Vector2* getCorners();
Vector2 getCenter();
bool Contains(Vector2& point);
bool Contains(Rectangle& rectangle);
bool Intersects(Rectangle& rectangle);
float X;
float Y;
float Width;
float Height;
};
#endif
我还在我的主目录中导入了 Circle.h 和 Rectangle.h.cpp
为了好玩:)矢量2.h:
#ifndef _SGE_Vector2_
#define _SGE_Vector2_
#include <GLFW/glfw3.h>
#include <math.h>
class Vector2
{
public:
Vector2();
Vector2(float x, float y);
bool operator == (const Vector2& a);
bool operator != (const Vector2& a);
Vector2 operator +(const Vector2& a);
Vector2 operator +=(const Vector2& a);
Vector2 operator -(const Vector2& a);
Vector2 operator -=(const Vector2& a);
Vector2 operator *(const float a);
Vector2 operator *=(const float a);
Vector2 operator /(const float a);
Vector2 operator /=(const float a);
float Length();
void Normalize();
~Vector2();
GLfloat X;
GLfloat Y;
};
#endif
"GLFW/glfw3.h" 包含一个函数:bool Rectangle(...); 当使用类 Rectangle 时会产生错误。 此问题有 2 种解决方案:
- 将类矩形重命名为其他名称,例如:矩形
- 创建一个命名空间,其中包含所有可以调用的类
using namespace X; //X is replaced by the name of your namespace
在主要用矩形类覆盖矩形函数中。
在萨朗的帮助下,问题得到了解决!
相关文章:
- 在CMake中使用find_package时,是否会显式包含标头
- GCC 包含标头(使用"-include")CMake 未检测到的更改
- 使用预处理指令检查是否包含标头?
- 更智能地在C++中包含保护,以便在不同的命名空间中多次包含标头
- 如何在 c++ 中有条件地包含标头?
- main.cpp 如何知道包含标头的源文件?
- 有没有办法告诉 g++ 编译器,而不是在某个 -I 路径中查找包含标头
- QT 如何包含标头和 cpp 文件
- 在 c++ 中,如果包含标头,为什么我会收到'does not a name of type'错误?
- CLion 无法解析类型 std::unordered_map,即使它提示我包含标头并且编译工作
- 为什么包含标头会导致"use of auto before deduction of auto"错误?
- 在 main.cpp 以外的文件中包含标头时出现链接器错误
- Visual Studio在STDAFX.H之前包含标头,会产生错误
- C2061 错误:"标识符",但我包含标头?
- 包含包含标头的目录时出现编译错误
- C++标头不能包含LNK2005错误
- 包含标头的C++错误
- C++:为什么在包含标头时收到"未在此范围内声明"错误?
- 包含标头如何导致链接器错误
- 错误:尽管包含标头,但尚未声明类,并且代码在其他地方编译良好