Sorry, this is an extremely complex program, and i was trying to avoid actually citing code if possible. I'll write an extremely simplified version to get the concept across. Keep in mind that these are all in their own files (as listed by the //<filename>// comments)
Code:
//<stdlib.h>//
class Base;
class Derived;
#include "Base.h"
#include "Derived.h"
Code:
//<Base.h>//
class Base
{
public:
static int sNum;
Base();
}
Code:
//<Base.cpp>//
#include "stdlib.h"
Base::Base()
{
//initialization stuff
}
Code:
//<Derived.h>//
class Derived : public Base
{
public:
Derived();
void Use();
}
Code:
//<Derived.cpp>//
#include "stdlib.h"
Derived::Derived()
{
//initialization stuff
}
void Derived::Use()
{
sNum = 5;
}
Code:
//<Main.cpp>//
#include "stdlib.h"
Base *b;
int main()
{
Derived *d = new Derived;
b = (Base*)d;
Base *b2 = new Base;
d->Use(); //sets sNum to 5;
cout<<Base::sNum<<endl;
cout<<b->sNum<<endl;
cout<<b2->sNum<<endl;
//should all output 5?
return 0;
}
It has always worked up to this point, but when i tried to use a static variable, i started getting problems. It compiles alright, but throws a linker error, that the static variable is an "unresolved external symbol". It doesnt list a specific line, or place in the code, since its a linker error, so i really have no idea what i'm doing wrong.
Please keep in mind that this is a simplified version and has to stay in the format shown.
Thanks in advance.