C
Chr?stian Rousselle
Hello,
I want to do derive a class from a Singleton template base class. Is
there a way to solve the following problem:
template<class T>
class CSingleton
{
public:
static T& GetInstance(void)
{
static T obj;
return obj;
}
protected:
virtual ~CSingleton() { };
CSingleton() {};
};
class App : public CSingleton<App>
{
protected:
App();
friend class CSingleton<App>; // otherwise c'tor cannot be
called
// is there a better way?
};
class App1 : public App
{
protected:
App1();
friend class CSingleton<App1>;
};
int main()
{
App1::GetInstance(); // App::GetInstance() is called
}
Is there a way to solve this? I do not like the friend deklaration and
I want to be able to create objects of type App1.
Thank you.
Christian Rousselle
I want to do derive a class from a Singleton template base class. Is
there a way to solve the following problem:
template<class T>
class CSingleton
{
public:
static T& GetInstance(void)
{
static T obj;
return obj;
}
protected:
virtual ~CSingleton() { };
CSingleton() {};
};
class App : public CSingleton<App>
{
protected:
App();
friend class CSingleton<App>; // otherwise c'tor cannot be
called
// is there a better way?
};
class App1 : public App
{
protected:
App1();
friend class CSingleton<App1>;
};
int main()
{
App1::GetInstance(); // App::GetInstance() is called
}
Is there a way to solve this? I do not like the friend deklaration and
I want to be able to create objects of type App1.
Thank you.
Christian Rousselle