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

前端 未结 4 808
不知归路
不知归路 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:55

    From the description of your problem ,the solution is far simpler.

    You have complicated a simple issue, just use

    class Nod   
    {  
    static int ctr;
    
    public: 
     int index;      
       Nod()
     {  
         ctr++;  //Increment the counter every time a object is created
     }
     Nod() {}   
    }; 
    
    
    //Allocate memory also
    
    int Nod::ctr;
    

    If there are more than 1 type of constructor, add the counter increment in every constructor.

提交回复
热议问题