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

compile error vba
compile error java
compile error excel
compile time error in python
syntax error
compiler
logical error
compile error unity

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 ?

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.

Difference between Compile Time Errors and Runtime Errors , This compiler error indicates something that must be fixed before the code can be compiled. All these errors are detected by compiler and thus are known as  Note Microsoft does not support downloading and installing add-ins from the Adobe Web site. If you need help, you must contact Adobe Technical Support. Method 2: Move the files

From snippet above I can't deduce something is wrong.

But typically this error means that you are including same header files multiple times. Don't you forget to add standard guards for include files?

#ifndef MY_HEADER_FILE_
#define MY_HEADER_FILE_

// here is your header file code

#endif

Errors in C/C++, A compile error happens when the compiler reports something wrong with your program, and does not produce a machine-language translation. You will get  Microsoft Visual Basic for Applications Compile error: The code in this project must be updated for use on 64-bit systems. Please review and update Declare statements and then mark them with the PtrSafe attribute.

You can have the definition of the structure on a header file. Have

 #pragma once

at the beginning of the header where the struct is defined, it solves the problem.

Compile errors and warnings, A compilation error is a message from your compiler that something is wrong, and it can't read your code. In more details, a compiler translate the set of symbols  Why does Compile Error in Hidden Module in Excel Appear? Microsoft is upgrading Office 2016 from 32-bit version to 64-bit version. This Compile Error in Hidden module error message usually appears when there are dome 32-bit add-ins versions of office which are incompatible with the newer version.

I had the same problem and luckily did not take long figure out that it was just a silly mistake.

The thing was that I had a backup of my project at another drive (D:) but all the code was set on the drive C: when explicitly defined the full path. I created it on the C: path and was always using that way, but accidentally opened the project from the D and thought that it was the same thing, so at compile it was including twice because in some cases it was including the code from the C: path and at others from the D: path.

What is a compilation error?, A run time error will only occur when the code is actually running. These are the most difficult - and lead to program crashes and bugs in your  Error - 'Compile Error: User-defined type not defined' occurs when attempting to compile code.

What is the difference between run-time error and compiler error , A compiler error indicates something that must be fixed before the code can be compiled. Example: You forget a semi-colon ( ; ) at the end of a statement and the​  I have this VBA code, when I try to run it, it gives me "Compile error: Syntax error" as can be seen in the image. I don't know VBA, what should i do to make this code work ? thanks. Sub

Compiler, Linker and Run-Time Errors, A compile time error is an error that occurs when GAUSS was trying to compile the program. These usually occur because the program is not a legal GAUSS  Compile-Time Errors: Errors that occur when you violate the rules of writing syntax are known as Compile-Time errors. This compiler error indicates something that must be fixed before the code can be compiled.

Compile Error vs Execute Error, Symptoms. When I try to play my scene in Unity it says all compiler errors must be fixed first. I don't know where to find the errors in my script. Compile error: The code in this project must be updated for use on 64-bit systems. Please review and update Declare statements and then mark them with the PtrSafe attribute."

Comments
  • See e.g. stackoverflow.com/questions/2979384/purpose-of-header-guards
  • It's probably in a file that's being included twice. Add pragma guards to the file it's in.
  • Clearly there is more to your program than this. Would you please reduce your program to the smallest complete program that exhibits the error you see, and then post that program here?
  • ... Use constructor initializer lists, Luke ...
  • +1 for likely answer, and another +1 for underscore advice. Unfortunately, capped at +1 overall.
  • +1 for the suggestion of avoiding leading underscores. For reasons that are not clear to me I see so many programmers that keep using those names when a similar approach (but always legal and less dangerous) would be for example adding them at the end instead.
  • @Oli Charlesworth: I've taken a look on the answer above and thats sounds reasonable. Will also remove them from my own code))