🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: alt.comp.lang.learn.c-c++
Article #456

Singleton pattern

#456
From: Max Coppin
Date: Sun, 20 Jan 2002 23:19
52 lines
2874 bytes
Hi,
I'm trying to convert one of my C++ programs to use the singleton pattern.
I've got the Design Patterns book by Gamma et all and am just trying to copy
a piece of code from that.  The code is below, as is the error i get.  My
first question is where should these pieces of code go?  I presume that the
definition goes in a .h and the implementation in a .cpp and then call in
from main.cpp or whatever.  Is this correct, can anyone help?

maxcoppin@btinternet.com



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

private:
 static MazeFactory* _instance;
};



MazeFactory* MazeFactory::_instance=0;

MazeFactory* MazeFactory::Instance()
{
 if(_instance == 0)
 {
  _instance= new MazeFactory;
 }
 return _instance;
}


ERROR MESSAGE :-

--------------------Configuration: ProjTemplate - Win32
Release--------------------
Compiling...
main.cpp
test.cpp
Generating Code...
Linking...
test.obj : error LNK2001: unresolved external symbol "protected: __thiscall
MazeFactory::MazeFactory(void)" (??0MazeFactory@@IAE@XZ)
Release/ProjTemplate.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

ProjTemplate.exe - 2 error(s), 0 warning(s)
Technical Details
Message-ID: <egI28.60178$WQ1.9314204@news6-win.server.ntlworld.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!supernews.com!news.tele.dk!small.news.tele.dk!212.74.64.35!colt.net!newspeer.clara.net!news.clara.net!news5-gui.server.ntli.net!ntli.net!news6-win.server.ntlworld.com.POSTED!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f7a5e,4f11b4295b82a2c5,start
X-Google-Attributes: gidf7a5e,public
X-Google-Thread: 109fba,4f11b4295b82a2c5,start
X-Google-Attributes: gid109fba,public
X-Google-Thread: 114592,4f11b4295b82a2c5,start
X-Google-Attributes: gid114592,public
X-Google-Thread: 110cb8,4f11b4295b82a2c5,start
X-Google-Attributes: gid110cb8,public
X-Google-Thread: 114af8,4f11b4295b82a2c5,start
X-Google-Attributes: gid114af8,public
X-Google-Thread: 104db2,4f11b4295b82a2c5,start
X-Google-Attributes: gid104db2,public
X-Google-ArrivalTime: 2002-01-20 15:24:53 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!supernews.com!news.tele.dk!small.news.tele.dk!212.74.64.35!colt.net!newspeer.clara.net!news.clara.net!news5-gui.server.ntli.net!ntli.net!news6-win.server.ntlworld.com.POSTED!not-for-mail
From: "Max Coppin" <maxcoppin@btinternet.com>
Newsgroups: alt.comp.lang.learn.c-c++,alt.language.patterns,borland.public.cpp.turbocpp,comp.lang.c++,comp.os.msdos.programmer.turbovision,comp.software.patterns
Subject: Singleton pattern
Lines: 55
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2600.0000
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000
Message-ID: <egI28.60178$WQ1.9314204@news6-win.server.ntlworld.com>
Date: Sun, 20 Jan 2002 23:19:36 -0000
NNTP-Posting-Host: 80.0.2.203
X-Complaints-To: abuse@ntlworld.com
X-Trace: news6-win.server.ntlworld.com 1011568778 80.0.2.203 (Sun, 20 Jan 2002 23:19:38 GMT)
NNTP-Posting-Date: Sun, 20 Jan 2002 23:19:38 GMT
Organization: ntl Cablemodem News Service