I'm having some trouble compiling/linking a set of classes, several of them dealing with a common global variable.
Basically, I declare and define a extern variable foo in class A and access/update it in classes B and C.
The relevant code looks like this:
A.h
extern string foo; // declare it <=== compiler error "storage class specified for foo"
B.cpp
include A.h
string foo; // define it
main () {
...
foo = "abc";
}
C.cpp
include A.h
cout << foo; // print it
My current error is "storage class specified for foo". But, I'm wondering if this is the correct approach. Should I be using a static variable? Any help much appreciated, as I've been on this for at least an hour by now.