linker error in singleton implementation

S

sam_cit

Hi everyone,

I have the following code and it gives a linker error on MS vc++ 6.0.

error LNK2001: unresolved external symbol "protected: __thiscall
Singleton::Singleton(void)" (??0Singleton@@IAE@XZ)

#include <stdlib.h>

class Singleton
{
public:
static Singleton* Instance();
protected:
Singleton();
Singleton(const Singleton&);
Singleton& operator= (const Singleton&);
private:
static Singleton* pinstance;
};

Singleton* Singleton::pinstance = 0;

Singleton* Singleton::Instance()
{
pinstance = new Singleton();
return pinstance;
}

int main()
{
Singleton::Instance();
return(0);
}

Can anyone help in this regard?
 
K

Kai-Uwe Bux

Hi everyone,

I have the following code and it gives a linker error on MS vc++ 6.0.

error LNK2001: unresolved external symbol "protected: __thiscall
Singleton::Singleton(void)" (??0Singleton@@IAE@XZ)

#include <stdlib.h>

class Singleton
{
public:
static Singleton* Instance();
protected:
Singleton();
Singleton(const Singleton&);
Singleton& operator= (const Singleton&);
private:
static Singleton* pinstance;
};

Singleton* Singleton::pinstance = 0;

Singleton* Singleton::Instance()
{
pinstance = new Singleton();

At this point, you attempt to create an instance using the default
constructor. However, that poor guy is not implemented :-(
return pinstance;
}

int main()
{
Singleton::Instance();
return(0);
}


Best

Kai-Uwe Bux
 
R

Rolf Magnus

Hi everyone,

I have the following code and it gives a linker error on MS vc++ 6.0.

error LNK2001: unresolved external symbol "protected: __thiscall
Singleton::Singleton(void)" (??0Singleton@@IAE@XZ)

#include <stdlib.h>

class Singleton
{
public:
static Singleton* Instance();
protected:
Singleton();

Where is the implementation for the above constructor?
 
?

=?ISO-8859-1?Q?Erik_Wikstr=F6m?=

Hi everyone,

I have the following code and it gives a linker error on MS vc++ 6.0.

error LNK2001: unresolved external symbol "protected: __thiscall
Singleton::Singleton(void)" (??0Singleton@@IAE@XZ)

#include <stdlib.h>

class Singleton
{
public:
static Singleton* Instance();
protected:
Singleton();
Singleton(const Singleton&);
Singleton& operator= (const Singleton&);
private:
static Singleton* pinstance;
};

Singleton* Singleton::pinstance = 0;

Singleton* Singleton::Instance()
{
pinstance = new Singleton();
return pinstance;
}

int main()
{
Singleton::Instance();
return(0);
}

Can anyone help in this regard?

Implement the constructor.
 
S

sam_cit

Implement the constructor.

Thanks everyone, and by the way i was just thinking of moving the
cons, copy cons and operator function to private section, wouldn't
that also server the purpose of singleton implementation?
 
?

=?ISO-8859-1?Q?Erik_Wikstr=F6m?=

Thanks everyone, and by the way i was just thinking of moving the
cons, copy cons and operator function to private section, wouldn't
that also server the purpose of singleton implementation?

Currently there's no real difference between having them protected and
private, you'd still have to implement the constructor. The only
difference would be if you inherit from Singleton, unless you plan to do
that you can have the private.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top