473,387 Members | 1,398 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

linker error in singleton implementation

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?

Jul 14 '07 #1
5 3794
sa*****@yahoo.co.in wrote:
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
Jul 14 '07 #2
sa*****@yahoo.co.in wrote:
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?
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?
Jul 14 '07 #3
On 2007-07-14 16:43, sa*****@yahoo.co.in wrote:
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.

--
Erik Wikström
Jul 14 '07 #4
On Jul 14, 8:14 pm, Erik Wikström <Erik-wikst...@telia.comwrote:
On 2007-07-14 16:43, sam_...@yahoo.co.in wrote:


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.

--
Erik Wikström- Hide quoted text -

- Show quoted text -
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?

Jul 14 '07 #5
On 2007-07-14 17:22, sa*****@yahoo.co.in wrote:
On Jul 14, 8:14 pm, Erik Wikström <Erik-wikst...@telia.comwrote:
>On 2007-07-14 16:43, sam_...@yahoo.co.in wrote:


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.

--
Erik Wikström- Hide quoted text -

- Show quoted text -

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.

--
Erik Wikström
Jul 14 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: cppaddict | last post by:
Hi, In this tutorial on singleton class in C++ (http://gethelp.devx.com/techtips/cpp_pro/10min/10min0200.asp) the author gives two implementations of a simple singleton class, claiming that...
10
by: ferdinand.stefanus | last post by:
Hi Could someone tell me what's the difference between these two singleton implementations: First implementation: class Singleton { public:
12
by: Baloff | last post by:
Hello I have this linker error which makes me think that the definition file is not being seen by the linker, this code is taken from "Thinking in C++, 2nd Edition, Volume 1, Annotated Solutions...
13
by: Robert W. | last post by:
At the beginning of my C# days (about 6 months ago) I learned about the Singleton pattern and implemented for Reference data, such as the kind that appears in an Options dialog box. My Singleton...
0
by: Tom McDermott | last post by:
I am having linker errors : error LNK2022: metadata operation failed (80131188) : Inconsistent field declarations in duplicated types This code linked sucessfully in C++.NET 2002, but does...
12
by: Preets | last post by:
Can anyone explain to me the exact use of private constructors in c++ ?
1
by: =?Utf-8?B?RmFiaWFu?= | last post by:
I have a native singleton in a C++/CLI dll. To compile the dll itself I put a declaration of the instance variable into the cpp file (otherwise the linker complains with a LNK 2020). I now want to...
3
by: stevewilliams2004 | last post by:
I am attempting to create a singleton, and was wondering if someone could give me a sanity check on the design - does it accomplish my constraints, and/or am I over complicating things. My design...
0
by: Matthew Fitzgibbons | last post by:
Urizev wrote: I've run into a similar problem. Basically, when you refer to a class from __main__ (i.e., the .py file you're actually running) versus from an imported module, Python doesn't...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.