0

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);
}

![enter image description here]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.

user2376997
  • 501
  • 6
  • 22
  • @codekaizer, I've edited my post with error log – user2376997 Jun 01 '18 at 07:23
  • 2
    Helpful hint: One of the tabs down at the bottom with Error List is Output. Output gives longer form error messages in text. Often the more verbose message gives you the extra hints you need to solve the problem. Not in this case, sadly, but perhaps useful in the future. – user4581301 Jun 01 '18 at 07:24

0 Answers0