T
tobias.sturn
Hi!
I have written this template for making a singleton:
#define DECLARE_SINGLETON(classname) \
private: \
static classname* m_pThis; \
classname(); \
class Guard \
{ \
public: \
~Guard() \
{ \
if(classname::m_pThis != 0 ) \
delete classname::m_pThis; \
} \
}; \
friend class Guard; \
public: \
static classname* getInstance();
#define DEFINE_SINGLETON(classname) \
classname* classname::m_pThis=0; \
classname* classname::getInstance() \
{ \
static Guard guard; \
if(m_pThis == 0) \
{ \
m_pThis = new classname(); \
} \
return m_pThis; \
}
Now i have a class which uses these macros but now i still i can write
constructors make them public and i have won nothing...
class Class
{
public:
Class(int a) {/*i have created an object */
Class(char a)...
};;
How could i make it not possible for the user of the template that he
cant override the constructor?
Thanks very much!!
I have written this template for making a singleton:
#define DECLARE_SINGLETON(classname) \
private: \
static classname* m_pThis; \
classname(); \
class Guard \
{ \
public: \
~Guard() \
{ \
if(classname::m_pThis != 0 ) \
delete classname::m_pThis; \
} \
}; \
friend class Guard; \
public: \
static classname* getInstance();
#define DEFINE_SINGLETON(classname) \
classname* classname::m_pThis=0; \
classname* classname::getInstance() \
{ \
static Guard guard; \
if(m_pThis == 0) \
{ \
m_pThis = new classname(); \
} \
return m_pThis; \
}
Now i have a class which uses these macros but now i still i can write
constructors make them public and i have won nothing...
class Class
{
public:
Class(int a) {/*i have created an object */
Class(char a)...
};;
How could i make it not possible for the user of the template that he
cant override the constructor?
Thanks very much!!