🔒 Locked
Multiple Definitions (C++)
Advertisement
Original Post
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?
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
=*=
#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
=*=
have you taken the answer and tried it?
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
quote:
I asked the question, because i was at school where i do not have a compiler i could try it with!!!
no, you asked the question because you hadn''t taken the time to try it before coming back with another question.
quote:
Original post by Ed C
What is your problem!!!!
You could at least try and find an answer to that question yourself before asking. Googlism comes up with a few suggestions: "pete wood is working in chorley", "pete wood is leaving the department to take up a position in australia" and "pete wood is the organiser".
(c:
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement