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

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.


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

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.

Tags:

C++