Здравствуйте, работаю с абстрактными фабриками поставили задание переделать ее под Синглтон. Вроде бы все сделал правильно но компилятор выдает: Ошибка LNK2001 неразрешенный внешний символ "private: static class WinterFactory * WinterFactory::instance" (?instance@WinterFactory@@0PAV1@A).
Код:
__interface IJacket
{
void wearOn();
string color();
};
class WinterJacket : public IJacket {
public:
void wearOn() {
cout << "This jacket is warm\n";
}
string color() {
return "grey";
}
};
class AutumnJacket : public IJacket {
public:
void wearOn() {
cout << "This jacket is comfortable\n";
}
string color() {
return "Yellow";
}
};
__interface IShoes {
void wearOn();
bool isSport();
};
class Sneakers : public IShoes {
public:
void wearOn() {
cout << "This sneakers are comfortable\n";
}
bool isSport() {
return true;
}
};
class Boots : public IShoes {
public:
void wearOn() {
cout << "This boots are warm\n";
}
bool isSport() {
return false;
}
};
__interface IFactory
{
IJacket* createJacket();
IShoes* createShoes();
};
class WinterFactory : public IFactory {
private:
static WinterFactory* instance;
WinterFactory() = default;
WinterFactory(const WinterFactory&) = delete;
public:
static WinterFactory* getInstance() {
if (instance == nullptr)
{
instance = new WinterFactory();
}
return instance;
}
IJacket* createJacket() {
return new WinterJacket();
}
IShoes* createShoes() {
return new Boots();
}
};
int main()
{
WinterFactory *WF = WinterFactory::getInstance();
}