Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Wondering why this is happening [C++]

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Stylo
Grandmaster Cheater Supreme
Reputation: 3

Joined: 16 May 2007
Posts: 1073
Location: Israel

PostPosted: Sat Aug 07, 2010 10:46 am    Post subject: Wondering why this is happening [C++] Reply with quote

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
View user's profile Send private message
Deltron Z
Expert Cheater
Reputation: 1

Joined: 14 Jun 2009
Posts: 164

PostPosted: Sat Aug 07, 2010 11:04 am    Post subject: Reply with quote

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
View user's profile Send private message
Stylo
Grandmaster Cheater Supreme
Reputation: 3

Joined: 16 May 2007
Posts: 1073
Location: Israel

PostPosted: Sat Aug 07, 2010 11:38 am    Post subject: Reply with quote

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
View user's profile Send private message
justa_dude
Grandmaster Cheater
Reputation: 23

Joined: 29 Jun 2010
Posts: 893

PostPosted: Sat Aug 07, 2010 12:46 pm    Post subject: Reply with quote

An example would help.

You probably want to be looking at wrapping your code in namespaces, though.
Back to top
View user's profile Send private message
Stylo
Grandmaster Cheater Supreme
Reputation: 3

Joined: 16 May 2007
Posts: 1073
Location: Israel

PostPosted: Sat Aug 07, 2010 1:01 pm    Post subject: Reply with quote

Well i'm guessing the problem was that i forgot to add
Code:

#ifndef _HEADER_
#define _HEADER_

//
//
//

#endif

to the other header file, works like a charm now Smile
thanks anywayz

_________________
Stylo
Back to top
View user's profile Send private message
Flyte
Peanuts!!!!
Reputation: 6

Joined: 19 Apr 2006
Posts: 1887
Location: Canada

PostPosted: Sat Aug 07, 2010 1:05 pm    Post subject: Reply with quote

To avoid this problem in the future you should redesign your program to not use globals.
Back to top
View user's profile Send private message
Stylo
Grandmaster Cheater Supreme
Reputation: 3

Joined: 16 May 2007
Posts: 1073
Location: Israel

PostPosted: Sat Aug 07, 2010 2:00 pm    Post subject: Reply with quote

Yeah i know globals pretty much ruin the program but when there's no choice there's no choice :\
_________________
Stylo
Back to top
View user's profile Send private message
NoMercy
Master Cheater
Reputation: 1

Joined: 09 Feb 2009
Posts: 289

PostPosted: Sun Aug 15, 2010 6:48 am    Post subject: Reply with quote

There is always a choice
Back to top
View user's profile Send private message
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Sun Aug 15, 2010 7:18 pm    Post subject: Reply with quote

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
View user's profile Send private message
Stylo
Grandmaster Cheater Supreme
Reputation: 3

Joined: 16 May 2007
Posts: 1073
Location: Israel

PostPosted: Thu Aug 19, 2010 9:05 am    Post subject: Reply with quote

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
View user's profile Send private message
Anden100
Grandmaster Cheater
Reputation: 0

Joined: 20 Apr 2007
Posts: 668

PostPosted: Thu Aug 19, 2010 2:25 pm    Post subject: Reply with quote

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 Wink
Back to top
View user's profile Send private message
Stylo
Grandmaster Cheater Supreme
Reputation: 3

Joined: 16 May 2007
Posts: 1073
Location: Israel

PostPosted: Thu Aug 19, 2010 3:35 pm    Post subject: Reply with quote

Anden100 wrote:
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 Wink

Got you Very Happy thx

_________________
Stylo
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites