0

I'm having 4 files in my project and when I try to compile it, I get this error:

error C2011: 'Details' : 'class' type redefinition

I think it's because I've used #include"AClass.cpp" three times in my files and it loads three times, but when I remove the two other #include"AClass.cpp", the compilation fails because AClass isn't found in that files.

Masious
  • 431
  • 5
  • 14
  • 1
    See http://stackoverflow.com/questions/8020113/c-include-guards – Dronz Dec 08 '14 at 22:48
  • 3
    Don't include `.cpp` files, those are supposed to be implementation files. You should only be including header files (usually `.h` or `.hpp`). – cdhowie Dec 08 '14 at 22:49

1 Answers1

1

As mentioned in the comments normally you don't include cpp-files at all. But anyway with header files you can run into the same situation. This is why most of the c++ headers are wrapped in the follwoing macro:

#ifndef SOME_HEADER_H
#define SOME_HEADER_H

class foo;

#endif //SOME_HEADER_H

For sure you have to replace SOME_HEADER with a unique name.

Of course there are situations (I had one of this cases short time ago), where you intend to include a header multiple times.. certain generics and some other magical things. But in general it is a good advise not to do so.

SeDav
  • 761
  • 7
  • 19