Jump to content
  • Advertisement
Sign in to follow this  
Azzazelus_13

dclaration files

This topic is 4198 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

This may sound stupid but i gotta do it. Since now I used only .h files for my classes. I want to make stuff corectly and to use .h for class instance, and .cpp for function declaration (for class members). like this: game.h ------ class game { public: void runGame(); } game.cpp -------- #include "game.h" void game::runGame() { } Main: ------ #include "game.cpp" I know its a common problem but hell i didnt manage to find the answer. I get linkage errors when i inlcude "stdafx.h" header in my game.cpp file error.obj : error LNK2005: "public: void __thiscall game::runGame()" (?GetID@error@@QAEXH@Z) already defined in boboS.obj Probbly because i call stdafx.h 2 times ? How can i solve this ?? Thanks you for your patience and time :)

Share this post


Link to post
Share on other sites
Advertisement
You should *never* include .cpp files. The whole point of header files is so that you can include declarations and not definitions. Change it to:

Main:
------
#include "game.h"

And that error should go away. What the error actually says is that the function game::runGame() is being compiled into 2 object files. Once for where the definition appears in game.cpp and once for where the preprocessor puts it in main.cpp.

For more info, read This article.

HTH

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!