global variable declaration

Joined
Feb 18, 2008
Messages
1
Reaction score
0
this question is more theory than useful, but i'm having trouble understanding this:

if i have three .cpp files, main.cpp class1.cpp and class2.cpp

i want to declare a global variable in main class1 and class2. i initialize it in main, and just use it in class1 and class2

main:
float pi = 3.14159;
class1:
extern float pi;
class2:
extern float pi;

but, what if i want to use the same global variable name and use it in main and class1, but give it a different value in class2?

main:
string type = green;
class1:
extern string type;
class2:
??

i want it to be global, and i want it to be a string named "type" but, for example, set equal to orange.

please explain! thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,263
Messages
2,571,064
Members
48,769
Latest member
Clifft

Latest Threads

Top