Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Ed C

Multiple Definitions (C++)

This topic is 5602 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

In my program i have three files: Main.cpp (contains main()) Russian.h (header file) Russian.cpp (implementation file for Russian.h) Both Main.cpp and Russian.cpp include Russian.h (#include "Russian.h") and Russian.h contains the definition of a global object of class CLib (CLib o_object. This creates an error when linking the files, because o_object is defined twice! How can i stop it being defined twice?

Share this post


Link to post
Share on other sites
Advertisement
Does russian.h have anything like

#if!defined RUSSIAN_H
#define RUSSIAN_H

//Code def''s would go in here

#endif



=*=
If things seem bad, think that they can get a whole load worse, and they don''t seem so bad anymore

=*=

Share this post


Link to post
Share on other sites
just to summarize the above:

Add in RUSSIAN.H:

#ifndef RUSSIAN_H
#define RUSSIAN_H

extern CLib o_object;
.
.
.

#endif


Add in RUSSIAN.CPP:

...
CLib o_object;
...

Share this post


Link to post
Share on other sites
Will that define o_object as a global object, because i want to use it in both Russian.cpp and Main.cpp.

Share this post


Link to post
Share on other sites
Thanks for the help everyone. Well...everyone except petewood. There was no need to speak to me like that.

Share this post


Link to post
Share on other sites
quote:
Original post by Ed C
Thanks for the help everyone. Well...everyone except petewood. There was no need to speak to me like that.

All you need is trying, and a warm happy face. There''s no need to... err... well, you should know. (See also: recursive)

Share this post


Link to post
Share on other sites
quote:
Ed C: Will that define o_object as a global object, because i want to use it in both Russian.cpp and Main.cpp.


No-one has answered this question yet, but you seem perfectly happy. That''s because you''ve realised that you''ve been given the correct answer. You have tried it and it has worked.

This is what I was suggesting you do. It''s a good way to learn.

Peace

Share this post


Link to post
Share on other sites
I asked the question, because i was at school where i do not have a compiler i could try it with!!!

Otherwise i would have tried it myself.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!