From all C++ online tutorials I've read that inner class can access outer class's static variables without references. I am getting LNK2001 error with this code when trying to asssign to static s_value
. Using VS2017 Community Ed. Any help?
class Outer {
int d_value;
static int s_value;
public:
class Inner {
public:
void foo(Outer & outer, int i) {
outer.d_value = i;
std::cout << "Outer's d_value: " << outer.d_value << std::endl;
s_value = i;
std::cout << "Outer's s_value: " << s_value << std::endl;
}
};
};
int main()
{
Outer outer;
Outer::Inner inner;
inner.foo(outer, 10);
}
]1
EDIT:
Thank you for routing me to the answer. I've added int Outer::s_value;
at the bottom of class Outer
. It runs.