Hello,
Suppose I have a class, MyClass, which contains variables (int x, y, z) which I want to access throughout my program. I want to be able to use the class in a static sense. I want to be able to access the variables using something like "MyClass::x", without actually having to create a MyClass object. So, I need to initialize these variables somewhere, which I gather requires the use of "extern".
Here is what I have so far:
But this is giving me a load of error messages, so the approach is obviously wrong. How should I go about it?Code:// myclass.cpp class MyClass { int x; int y; int z; }; // main.cpp int main() { extern MyClass::x = 4; extern MyClass::y = 5; extern MyClass::z = 8; return 0; }
Thanks