Answer the question
In order to leave comments, you need to log in
How to solve LNK2001 error?
Hello, I work with abstract factories and set the task to remake it under Singleton. It seems that everything was done correctly, but the compiler produces: Error LNK2001 unresolved external symbol "private: static class WinterFactory * WinterFactory::instance" ([email protected]@@[email protected]).
The code:
__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();
}
Answer the question
In order to leave comments, you need to log in
Under the factory class, add
It wouldn't hurt to format the code and replace it with . Also, the use of pointers does not make sense (especially raw ones).
WinterFactory* WinterFactory::instance = nullptr;
__interface
class
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question