It compiles fine and when link I am getting this error
1>GLoader1.obj : error LNK2005: "bool HeightFunction::initialized" (?initialized@HeightFunction@@3_NA) already defined in GLoader.obj
1>GLoader1.obj : error LNK2005: "class Ogre::RaySceneQuery * HeightFunction::raySceneQuery" (?raySceneQuery@HeightFunction@@3PAVRaySceneQuery@Ogre@@A) already defined in GLoader.obj
1>GLoader1.obj : error LNK2005: "class HeightFunction::MyRaySceneQueryListener * HeightFunction::raySceneQueryListener" (?raySceneQueryListener@HeightFunction@@3PAVMyRaySceneQueryListener@1@A) already defined in GLoader.obj
1>GLoader1.obj : error LNK2005: "class Ogre::Ray HeightFunction::updateRay" (?updateRay@HeightFunction@@3VRay@Ogre@@A) already defined in GLoader.obj
1>GLoader1.obj : error LNK2005: "void __cdecl HeightFunction::initialize(class Ogre::SceneManager *)" (?initialize@HeightFunction@@YAXPAVSceneManager@Ogre@@@Z) already defined in GLoader.obj
1>bin\Release\TheGameProject.exe : fatal error LNK1169: one or more multiply defined symbols found
You've added a function outside of a class, defined in the header file that isn't marked as inline so is getting defined in multiple classes when it is compiled.
void initialize(SceneManager *sceneMgr)
Either:
Mark that function as inline
Create a HeightFunction.cpp file and move the definition of that function in there, and change the code in HeightFunction.h to just be a declaration
Seriously, I give you two choices and you somehow manage to do both of them.
Remove the 'inline' keyword from everything, since they are certainly no longer inline since they are in a separate file. If you still get the linker error after that, try doing a full rebuild, if that still fails, get back to me.
1>Linking...
1>GLoader1.obj : error LNK2005: "bool HeightFunction::initialized" (?initialized@HeightFunction@@3_NA) already defined in GLoader.obj
1>GLoader1.obj : error LNK2005: "class Ogre::RaySceneQuery * HeightFunction::raySceneQuery" (?raySceneQuery@HeightFunction@@3PAVRaySceneQuery@Ogre@@A) already defined in GLoader.obj
1>GLoader1.obj : error LNK2005: "class MyRaySceneQueryListener * HeightFunction::raySceneQueryListener" (?raySceneQueryListener@HeightFunction@@3PAVMyRaySceneQueryListener@@A) already defined in GLoader.obj
1>GLoader1.obj : error LNK2005: "class Ogre::Ray HeightFunction::updateRay" (?updateRay@HeightFunction@@3VRay@Ogre@@A) already defined in GLoader.obj
1>HeightFunction.obj : error LNK2005: "bool HeightFunction::initialized" (?initialized@HeightFunction@@3_NA) already defined in GLoader.obj
1>HeightFunction.obj : error LNK2005: "class Ogre::RaySceneQuery * HeightFunction::raySceneQuery" (?raySceneQuery@HeightFunction@@3PAVRaySceneQuery@Ogre@@A) already defined in GLoader.obj
1>HeightFunction.obj : error LNK2005: "class MyRaySceneQueryListener * HeightFunction::raySceneQueryListener" (?raySceneQueryListener@HeightFunction@@3PAVMyRaySceneQueryListener@@A) already defined in GLoader.obj
1>HeightFunction.obj : error LNK2005: "class Ogre::Ray HeightFunction::updateRay" (?updateRay@HeightFunction@@3VRay@Ogre@@A) already defined in GLoader.obj
1>LINK : warning LNK4098: defaultlib 'LIBCMT' conflicts with use of other libs; use /NODEFAULTLIB:library
1>bin\Release\TheGameProject.exe : fatal error LNK1169: one or more multiply defined symbols found
Ah of course *smacks head* I forgot you had variables inside your header file, yeah, that would cause that.
If you need those variables to be available in other places besides HeightFunction.cpp, then you can either make them static or extern, if you just need to use them in the cpp file then it's fine to leave them as they are.
Basically, when you include a file anywhere in code, all the C++ pre-processor does is dump the contents of that file into the file you included it in, this means that anything like variables and functions that are defined in the header file get copied into multiple compilation units, so when the linker tries to link it finds multiple versions of the same thing, and gets confused.
You can get around this by marking variables as static or extetn (look up on Google for the difference, I would explain but I have to leave in 5 minutes), and by either marking functions defined in a header to be inline or static, or by separating the function so that just the declaration is inside the header, and the definition is inside another cpp file.
Basically, when you include a file anywhere in code, all the C++ pre-processor does is dump the contents of that file into the file you included it in, this means that anything like variables and functions that are defined in the header file get copied into multiple compilation units, so when the linker tries to link it finds multiple versions of the same thing, and gets confused.
Now I have better understand of what really happened.
I have tried both static and extern. For static it works fine but extern still make the same error.