Hello,
I want to create a generic var, that could be from one class or another class.
In this code sample I want that var aa be generic so in my code I can access code from class A or class B.
But aa MUST BE GLOBAL.
Could you help me?
class MyClass
{
public:
MyClass() {} //contructor padrão, não deve ser utilizado isoladamente
static MyClass* getInstance()
{
static MyClass *instance = 0;
if (!instance) instance = new MyClass();
return instance;
}
};
class A : public MyClass
{
public:
int a() { return 1; }
};
class B : public MyClass
{
public:
int b() { return 1; }
};
template <class TAIT> class AIT
{
public:
static TAIT& Instance()
{
static TAIT instance;
return instance;
}
};
AIT aa;
void main()
{
aa.Instance().a(); // or
aa.Instance().b(); // aa could be class
// A or class B. So I could access
// function a or function b (not at same
// time, of course)
return;
}