Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compile error "'struct' type redefinition" although it's the first definition for it

Tags:

c++

Everything was working well untill I moved some code from the main file to a new class, then I had the following error:

error C2011: 'color1' : 'struct' type redefinition

struct color1
{
    color1()
    {
        red = green = blue = 0;
    }

    color1(float _red, float _green, float _blue)
    {
        red = _red;
        green = _green;
        blue = _blue;
    }

    float red, green, blue;
};

Any idea ?

like image 218
Homam Avatar asked Apr 28 '11 21:04

Homam


1 Answers

If the compiler says it's redefined, then it probably is.

My psychic debugging skills tell me that you moved the struct from a source file to a header file, and forget the include guards in that header, which is then included multiple times in a source file.

EDIT: As a general rule I generally suggest avoiding leading underscores. In some cases (for example followed by a capital letter) they're reserved for the implementation and it's simplest to just never use leading _ instead of hoping you remember all the rules.

like image 78
Mark B Avatar answered Nov 08 '22 01:11

Mark B