Re: Problem with Singleton template (2)
On Sep 1, 3:46 pm, DavidA <dandbn...@talktalk.net> wrote:
On 30 Aug, 16:28, Bart van Ingen Schenau <b...@ingen.ddns.info> wrote:
The easiest hack, but also a maintenance nightmare, is like this
--- singleton.cpp ---
#include "singleton.h"
template <class T>
static T* Singleton<T>::mp_instance;
Sadly, the compiler complains about the above declaration:
"... error: a storage class may not be specified here
I think I'm just going to have to give up on a Singleton template
under this compiler.
{ Edits: quoted mod comment, signature and clc++m banner removed. -mod }
before giving up so easy:), why don't you try to define the static
pointer in your cpp file like this:
in some header you have:
typedef MyList< int > IntList_t;
typedef MyList< double > DoubleList_t;
in your .cpp, where you first call the instance() on a type, let's say
int list:
IntList_t * Singleton< IntList_t >::mp_instance_ = 0L;
in your .cpp file where you first call instance() on let's say
DoubleList:
DoubleList_t * Singleton< DoubleList_t >::mp_instance_ = 0L;
I think even your compiler should swallow this because you tell it now
exactly what type of static member you want to initialize and you even
tell it where to put ut (in which translation unit).
it seems to me that your compiler cannot expand
template <class T> static T* Singleton<T>::mp_instance;
to used types so you will have to specifically tell it what
specializations of Singleton are you going to use like in:
DoubleList_t * Singleton< DoubleList_t >::mp_instance_ = 0L;
cheers,
gil
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]