| View previous topic :: View next topic |
| Author |
Message |
Stylo Grandmaster Cheater Supreme
Reputation: 3
Joined: 16 May 2007 Posts: 1073 Location: Israel
|
Posted: Sat Aug 07, 2010 10:46 am Post subject: Wondering why this is happening [C++] |
|
|
I'm keep getting this error
| Code: |
one or more multiply defined symbols found.
<my var name> already defined in Main.obj.
|
i guess it's because i include the .h file few times at more than one .cpp file
but at the .h file i remembered to do that
| Code: |
#ifndef _HEADER_
#define _HEADER_
//
//
// etc code
//
//
#endif
|
but still getting the same message
i forgot how come it's happening?!
_________________
Stylo |
|
| Back to top |
|
 |
Deltron Z Expert Cheater
Reputation: 1
Joined: 14 Jun 2009 Posts: 164
|
Posted: Sat Aug 07, 2010 11:04 am Post subject: |
|
|
Did you define a variable with the same name in the CPP file?
And did you define the variable in the header file as "extern"?
|
|
| Back to top |
|
 |
Stylo Grandmaster Cheater Supreme
Reputation: 3
Joined: 16 May 2007 Posts: 1073 Location: Israel
|
Posted: Sat Aug 07, 2010 11:38 am Post subject: |
|
|
I defined the variable inside the header file that i included at other header file which i include to my main.cpp file
but when i set that variable inside the .cpp that include the specific header it's all ok.
plus i got another question
lets say i got a class (header + cpp files) and i include it from my main.cpp (so far all good)
but when i create another header + cpp files for some other purposes and include the new header file in my class's header file it's all messy and errorsi
i'll give an example code if u didn't understand
_________________
Stylo |
|
| Back to top |
|
 |
justa_dude Grandmaster Cheater
Reputation: 23
Joined: 29 Jun 2010 Posts: 893
|
Posted: Sat Aug 07, 2010 12:46 pm Post subject: |
|
|
An example would help.
You probably want to be looking at wrapping your code in namespaces, though.
|
|
| Back to top |
|
 |
Stylo Grandmaster Cheater Supreme
Reputation: 3
Joined: 16 May 2007 Posts: 1073 Location: Israel
|
|
| Back to top |
|
 |
Flyte Peanuts!!!!
Reputation: 6
Joined: 19 Apr 2006 Posts: 1887 Location: Canada
|
Posted: Sat Aug 07, 2010 1:05 pm Post subject: |
|
|
| To avoid this problem in the future you should redesign your program to not use globals.
|
|
| Back to top |
|
 |
Stylo Grandmaster Cheater Supreme
Reputation: 3
Joined: 16 May 2007 Posts: 1073 Location: Israel
|
Posted: Sat Aug 07, 2010 2:00 pm Post subject: |
|
|
Yeah i know globals pretty much ruin the program but when there's no choice there's no choice :\
_________________
Stylo |
|
| Back to top |
|
 |
NoMercy Master Cheater
Reputation: 1
Joined: 09 Feb 2009 Posts: 289
|
Posted: Sun Aug 15, 2010 6:48 am Post subject: |
|
|
| There is always a choice
|
|
| Back to top |
|
 |
hcavolsdsadgadsg I'm a spammer
Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
Posted: Sun Aug 15, 2010 7:18 pm Post subject: |
|
|
| Stylo wrote: | | Yeah i know globals pretty much ruin the program but when there's no choice there's no choice :\ |
In which case you need to redesign.
|
|
| Back to top |
|
 |
Stylo Grandmaster Cheater Supreme
Reputation: 3
Joined: 16 May 2007 Posts: 1073 Location: Israel
|
Posted: Thu Aug 19, 2010 9:05 am Post subject: |
|
|
| slovach wrote: | | Stylo wrote: | | Yeah i know globals pretty much ruin the program but when there's no choice there's no choice :\ |
In which case you need to redesign. |
I never said i need to redesign my code, just said that there are some cases i should use global vars.
_________________
Stylo |
|
| Back to top |
|
 |
Anden100 Grandmaster Cheater
Reputation: 0
Joined: 20 Apr 2007 Posts: 668
|
Posted: Thu Aug 19, 2010 2:25 pm Post subject: |
|
|
| Stylo wrote: | | slovach wrote: | | Stylo wrote: | | Yeah i know globals pretty much ruin the program but when there's no choice there's no choice :\ |
In which case you need to redesign. |
I never said i need to redesign my code, just said that there are some cases i should use global vars. |
And slovach then said, that if you need to use Global Variables, its because of your program being badly designed, and therefore will need a redesign. So by saying you have no choise, but to use global variables, you say you need to redesign your code
|
|
| Back to top |
|
 |
Stylo Grandmaster Cheater Supreme
Reputation: 3
Joined: 16 May 2007 Posts: 1073 Location: Israel
|
|
| Back to top |
|
 |
|