-1

The title might be unclear but the code is simple and should explain itself. I would like to typedef a constructor to my class inside the class and then set the address of said constructor elsewhere.

class Dog {
public:
    typedef Dog* (__thiscall* Constructor_T)(Dog* thisptr);
    static Constructor_T Constructor;

    Dog() {
        Constructor(this);
    }
};

void SetDogConstructor() {
    Dog::Constructor = (Dog::Constructor_T)0x1234;
}

The error I receive is:

Error   2   error LNK2001: unresolved external symbol "public: static class Dog * (__thiscall* Dog::Constructor)(class Dog *)" (?Constructor@Dog@@2P6EPAV1@PAV1@@ZA)
Dalton Sandbothe
  • 501
  • 2
  • 7
  • 16

1 Answers1

1

A static member needs a definition outside the class. In your case, you would put

Dog::Constructor_T Dog::Constructor = nullptr;

in Dog.cpp.

aschepler
  • 70,891
  • 9
  • 107
  • 161