Article View: alt.comp.lang.learn.c-c++
Article #459Re: Singleton pattern
From: Robert C. Martin
Date: Wed, 23 Jan 2002 18:27
Date: Wed, 23 Jan 2002 18:27
71 lines
3410 bytes
3410 bytes
On Sun, 20 Jan 2002 23:19:36 -0000, "Max Coppin"
<maxcoppin@btinternet.com> wrote:
>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
>
Try adding the line below:
>
>class MazeFactory
>{
>public:
> static MazeFactory* Instance();
>protected:
> MazeFactory();
>
>private:
> static MazeFactory* _instance;
>};
>
//Add this line
MazeFactory::MazeFactory() {}
>
>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)
>
>
Robert C. Martin | "Uncle Bob" | Software Consultants
Object Mentor Inc. | rmartin@objectmentor.com | We'll help you get
PO Box 5757 | Tel: (800) 338-6716 | your projects done.
565 Lakeview Pkwy | Fax: (847) 573-1658 | www.objectmentor.com
Suite 135 | | www.XProgramming.com
Vernon Hills, IL, | Training and Mentoring | www.junit.org
60061 | OO, XP, Java, C++, Python|
"One of the great commandments of science is:
'Mistrust arguments from authority.'" -- Carl Sagan
Technical Details
Message-ID:
<l20u4ukdk997unoujkbhb0sbg9ffr4ijme@4ax.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-post-01!supernews.com!news.supernews.com!not-for-mailReferences:
<egI28.60178$WQ1.9314204@news6-win.server.ntlworld.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f7a5e,4f11b4295b82a2c5 X-Google-Attributes: gidf7a5e,public X-Google-Thread: 110cb8,4f11b4295b82a2c5 X-Google-Attributes: gid110cb8,public X-Google-Thread: 114af8,4f11b4295b82a2c5 X-Google-Attributes: gid114af8,public X-Google-Thread: 109fba,4f11b4295b82a2c5 X-Google-Attributes: gid109fba,public X-Google-Thread: 114592,4f11b4295b82a2c5 X-Google-Attributes: gid114592,public X-Google-Thread: 104db2,4f11b4295b82a2c5 X-Google-Attributes: gid104db2,public X-Google-ArrivalTime: 2002-01-23 10:26:55 PST Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-post-01!supernews.com!news.supernews.com!not-for-mail From: Robert C. Martin <rmartin @ objectmentor . 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: Re: Singleton pattern Date: Wed, 23 Jan 2002 12:27:15 -0600 Organization: Object Mentor Inc. Message-ID: <l20u4ukdk997unoujkbhb0sbg9ffr4ijme@4ax.com> Reply-To: rmartin @ objectmentor . com References: <egI28.60178$WQ1.9314204@news6-win.server.ntlworld.com> X-Newsreader: Forte Agent 1.8/32.553 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Complaints-To: newsabuse@supernews.com Lines: 71