error C2011: '' : 'class' type redefinition

user3164272 picture user3164272 · Sep 7, 2014 · Viewed 69.9k times · Source

One of the header files is as follows -

#include "stdafx.h"

class AAA
{
public:
    std::string strX;
    std::string strY;
};

When I try to compile the project, I get the error

error C2011: 'AAA' : 'class' type redefinition

Nowhere else in my program have I redefined the class AAA. How do I fix this?

Answer

Ashot picture Ashot · Sep 7, 2014

Change to code to something like this:

#ifndef AAA_HEADER
#define AAA_HEADER

#include "stdafx.h"

class AAA
{
public:
    std::string strX;
    std::string strY;
};

#endif

If you include this header file more than once in some source file, include guards will force compiler to generate class only once so it will not give class redefinition error.