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?
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