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 oxygen{
class ImpFactory{
public:
static boost::shared_ptr<ImpFactory> GetInstance();
private:
static boost::shared_ptr<ImpFactory> mInstance;
};
and here's the .cpp file:
#include "impfactory.h"
using namespace oxygen;
using namespace boost;
shared_ptr<ImpFactory> ImpFactory::GetInstance(){
if (mInstance.get() == 0)
mInstance = shared_ptr<ImpFactory>(new ImpFactory());
return mInstance;
}
The code compiles, but I get a linker error:
../../lib/oxygen/liboxygen.so.3.2.4: undefined reference to `oxygen::ImpFactory::mInstance'
This currently has three students stumped. Any ideas?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…