Re: [Dev-C++] undefined reference to ...
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Hossein H. <ult...@em...> - 2003-11-02 11:21:32
|
Dear Philippe,
> Anyone know why this doesn't work... I cut the problem to this simple
> form, only one source file (main.cpp). I'm getting an undefined
> reference to foo::m_instance. If m_instance were not defined as static
> all would be ok.
>
> I'm using Dev-cpp ver 4.9.8.3
>
> Help appreciated...
>
>
> #include <iostream>
> #include <stdlib.h>
>
> using namespace std;
>
> class foo {
> private:
> static foo* m_instance;
> public:
> static foo* Instance();
> };
>
> foo* foo::Instance()
> {
> if (m_instance == NULL)
Is the error occuring here? If yes, it seems to be a run-time error, huh? If the answer is
again yes, hmmm..., it seems to be arisen because of the fact that the static members must
be initialised outside any body in programme.
> m_instance = new foo;
> return m_instance;
> }
Try this one, for example:
class Foo{/*Whatever it was*/};
foo* Foo::m_instance = new foo;
Regards,
--Hossein
PS: Is this assumed to be a "Singleton" holder class? If yes, why not using the excellent
implelmented free ones? E.g., you can use Loki::SingletonHolder which can be freely
downloaded from http://www.moderncppdesign.com. I'm not sure, but it seems that there must
be some similar stuff in the Boost's gient repositary. (http://www.boost.org)
--
__________________________________________________________
Sign-up for your own personalized E-mail at Mail.com
http://www.mail.com/?sr=signup
CareerBuilder.com has over 400,000 jobs. Be smarter about your job search
http://corp.mail.com/careers
|