0
#include <forward_list>

using namespace std; 

class Test {
public:
    Test(){objects.push_front(this);}
private:
    static forward_list<Test*>objects; 
};

int main(){
    Test a; 
}//Visual Studio 17, error

Visual studio doesn't say what the problem is. It just retruns these two codes - LNK1120 and LNK2001.

baduker
  • 19,152
  • 9
  • 33
  • 56

1 Answers1

4

You have an undefined reference to static forward_list<Test*>objects; You have to define your static object like this:

#include <forward_list>

using namespace std; 

class Test {
public:
    Test(){objects.push_front(this);}
private:
    static forward_list<Test*>objects; 
};

forward_list<Test*> Test::objects;

int main(){
    Test a; 
}//Visual Studio 17, error
Amadeusz
  • 1,488
  • 14
  • 21