lakshmivaragan
Programmer
Is there a way I could store multiple objects of different types in a container, say, a vector or map or an array?
e.g
template <class T>
class Holder
{
public:
T * m_ptr;
Holder(T * ptr)
{
m_ptr = ptr;
}
};
class Cls1
{
xxx...
};
class Cls2
{
xxx...
};
class Cls3
{
xxx...
};
int main()
{
Cls1 ptr1 = new Cls1;
Cls2 ptr2 = new Cls2;
Cls3 ptr3 = new Cls3;
Holder<Cls1> hobj1(ptr1);
Holder<Cls2> hobj2(ptr2);
Holder<Cls3> hobj3(ptr3);
//How to store the holder objects hobj1, hobj2, hobj3
// in a STL container or array?
}
e.g
template <class T>
class Holder
{
public:
T * m_ptr;
Holder(T * ptr)
{
m_ptr = ptr;
}
};
class Cls1
{
xxx...
};
class Cls2
{
xxx...
};
class Cls3
{
xxx...
};
int main()
{
Cls1 ptr1 = new Cls1;
Cls2 ptr2 = new Cls2;
Cls3 ptr3 = new Cls3;
Holder<Cls1> hobj1(ptr1);
Holder<Cls2> hobj2(ptr2);
Holder<Cls3> hobj3(ptr3);
//How to store the holder objects hobj1, hobj2, hobj3
// in a STL container or array?
}