Static member error in c++

别来无恙 提交于 2019-12-08 02:23:40

问题


I am trying to define a static member pointer in C++. However I get a linker error. The error is

1>main.obj : error LNK2001: unresolved external symbol "public: static class Activity * * Solution::temp" (?temp@Solution@@2PAPAVActivity@@A)

1>Solution.obj : error LNK2001: unresolved external symbol "public: static class Activity * * Solution::temp" (?temp@Solution@@2PAPAVActivity@@A)

Code:

class Solution{

public:
    Activity **solution;

    Solution();
    Solution(Activity **list, bool direction);
    static Activity** temp;
};

Activity is another class. How can I solve this problem?


回答1:


You have to add the definition:

Activity** Solution::temp = 0;

to the file that implements the class Solution.



来源:https://stackoverflow.com/questions/7939491/static-member-error-in-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!