FORUM CLOSED, PLEASE REGISTER AT FORUM.SIO2INTERACTIVE.COM
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Make a global variable private

4 posters

Go down

Make a global variable private Empty Make a global variable private

Post  Smittens 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

Back to top Go down

Make a global variable private Empty Re: Make a global variable private

Post  uprise78 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

Back to top Go down

Make a global variable private Empty Re: Make a global variable private

Post  meteors Wed Feb 11, 2009 12:01 pm

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


Best,
-joshua
meteors
meteors

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

Back to top Go down

Make a global variable private Empty Re: Make a global variable private

Post  oioioi 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

Back to top Go down

Make a global variable private Empty Re: Make a global variable private

Post  Sponsored content


Sponsored content


Back to top Go down

Back to top

- Similar topics

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