Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error C2011: 'XX' : 'class' type redefinition

Tags:

c++

class

I have this compiler error (C2011) with this piece of code. I don't know what is wrong with it.

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;
};
like image 634
Pacha Avatar asked Jan 04 '13 20:01

Pacha


1 Answers

Include guards:

#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.

The alternative is using

#pragma once

but this isn't supported by all compilers.

like image 182
Luchian Grigore Avatar answered Oct 21 '22 16:10

Luchian Grigore