Consider following MRE:
class Segment
{
public:
void update();
};
class Singleton
{
Singleton();
public:
static Singleton& get_instance();
void complete();
};
void Segment::update()
{
Singleton::get_instance().complete();
}
Singleton& Singleton::get_instance()
{
static Singleton instance;
return instance;
}
void Singleton::complete()
{}
int main()
{
return 0;
}
When I compile the code under standard Debug configuration in VS2019, I get a linker error about unresolved external for function get_instance()
.
Full error description
LNK1120 1 unresolved externals
LNK2019 unresolved external symbol
"private: __cdecl Singleton::Singleton(void)"
(??0Singleton@@AEAA@XZ) referenced in function
"public: static class Singleton & __cdecl Singleton::get_instance(void)"
(?get_instance@Singleton@@SAAEAV1@XZ)
I declared the classes first, then I implemented all the methods so what's wrong?