Make a global variable private

View previous topic View next topic Go down

Make a global variable private

Post  Smittens on Wed Feb 11, 2009 12:12 am

Hi,

I'm modifying one of the tutorials, and trying to use two similar (duplicated the files, but they're different) copies of template.mm/template.h. Although I'd like to keep the variables declared at the top named the same, this is causing a linking error.

Basically I'm looking for a way to make them private, but just doing

"private bool startGame" causes an error.

I know this isn't specifically an sio2 problem but any help would be greatly appreciated!

Smittens

Posts : 1
Join date : 2009-02-11

View user profile

Back to top Go down

Re: Make a global variable private

Post  uprise78 on Wed Feb 11, 2009 10:17 am

There is no such thing as private in C. You need to use C++ to get private vars. You can use the static keyword inside a block to make the variable only available in that block but from the sounds of it you just need to rename one of the vars.

uprise78

Posts : 228
Join date : 2008-10-31

View user profile

Back to top Go down

Re: Make a global variable private

Post  meteors on Wed Feb 11, 2009 12:01 pm

You can use all of the C++ techniques for compartmentalization, including namespaces, and 'extern'.


Best,
-joshua
avatar
meteors

Posts : 241
Join date : 2008-11-08
Location : Sunny Florida

View user profile

Back to top Go down

Re: Make a global variable private

Post  oioioi on Wed Feb 11, 2009 12:10 pm

I don't know exactly what you want but if you want a variable to only be accessed from one file you can put it in the .c file like this:
Code:
#include "../src/sio2/sio2.h"
int something;
bool smoethingmore;
these variables will be scoped to that file, I think... You could also make a class. However I might misunderstood you.

oioioi

Posts : 136
Join date : 2008-12-02
Location : Norway

View user profile

Back to top Go down

Re: Make a global variable private

Post  Sponsored content


Sponsored content


Back to top Go down

View previous topic View next topic Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum