i have 3 files: classes.h (just class declerations), classes.cpp(function definitions of the classes in classes.h) and main.cpp... classes.cpp includes classes.h and main.cpp includes classes.cpp only. when i compile i receive redefinition error. what should i do? Here is the 2 errors:
---------------------------------------------------------------------
1>cylApp.obj : error LNK2005: "public: __thiscall Cube::Cube(void)" (??0Cube@@QAE@XZ) already defined in classes.obj
1>cylApp.obj : error LNK2005: "public: virtual void __thiscall Cube::Draw(void)" (?Draw@Cube@@UAEXXZ) already defined in classes.obj
---------------------------------------------------------------------
====================================
classes.h is below
====================================
#include <glut.h>
Note:
It's possible to include any file (so also a cpp file) #include "something" inerts the file contents in that point of the code.
If you are including a cpp file and passing it to the compiler, its code would be compiled twice generating linker errors as symbols defined in it will result to be defined more than once.
For this reason you should only include header files
That is correct. When you #include classes.cpp, it puts all of the function bodies in main.cpp as well as in classes.cpp. Therefore the linker finds two seperate function bodies and it doesn't know which one to use.