本文介绍了错误C2011:'XX':'类'类型重新定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个编译器错误(C2011)与这段代码。
I have this compiler error (C2011) with this piece of code. I don't know what is wrong with it.
命名空间(Ogre)没有 PlaneMovement $ c $的定义c>。我也尝试了不同的名称,但仍然有相同的错误。
The namespace (Ogre) doesn't have a definition for PlaneMovement
. I also tried a different name and still the same errors.
#include <Ogre.h>
using namespace Ogre;
class PlaneMovement
{
public:
PlaneMovement(Degree startingAngle, Real velocity = 2, Real gravity = 2);
Vector2 updateMovement(const FrameEvent& evt);
private:
Degree currentAngle;
Real currentVelocityX;
Real currentVelocityY;
Real gravity;
bool top;
};
推荐答案
包含警卫:
#ifndef FILE_H
#define FILE_H
//file contents here
#endif
头文件应该包含警告,因为这个确切的原因 - 多个包含在同一个翻译单元可以导致多个定义。
Header files should have include guards for this exact reason - multiple inclusion in the same translation unit can lead to a multiple definition.
替代方法是使用
#pragma once
,但并非所有编译器都支持。
but this isn't supported by all compilers.
这篇关于错误C2011:'XX':'类'类型重新定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!