Static constructor in c++ and fatal error LNK1120: 1 unresolved externals

前端 未结 4 765
不知归路
不知归路 2021-01-23 23:36

To start with i should probably let you know that i am by no means a programmer, and i\'m just doing this for a homework assignment, so if it\'s possible i will require a really

4条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-23 23:54

    The problem is that Nod::ctr is only declared but not defined.

    class Nod
    {
        // Declare the counter variable
        static counter ctr;
    
        ...
    };
    
    // Define the counter variable
    counter Nod::ctr;
    

    The definition should of course be in a source file, not a header file, or you will get multiple definition errors instead.

提交回复
热议问题