C++: Undefined reference to instance in Singleton class

前端 未结 5 1280
醉酒成梦
醉酒成梦 2020-12-20 17:15

I\'m currently trying to implement a factory as a singleton. I practically used the textbook example of the Singleton pattern. Here\'s the .h file:

namespace         


        
5条回答
  •  天涯浪人
    2020-12-20 17:40

    You must define the static instance, not just declare it. The definition creates the actual object you refer to.

    In your cpp file, add the line:

    boost::shared_ptr ImpFactory::mInstance;
    

提交回复
热议问题