P
Prakash Bande
Hi,
I have a template class as below:
template <class _T> class myclass{
public:
myclass(){ obj = new _T();}
_T* obj;
_T* operator->() (return obj;}
};
I need to keep all the myclass objects in a STL container such as
vector. But since every instantiation is a different type I cannot
have a vector or myclass.
So I derived myclass from a base class as below:
class base{
public:
base(){}
~base(){}
};
template class<_T> myclass : public base
Now I have a vector of base objects.
The problem is that I want to call -> operator. I cannot make it pure
virtual in base since the return type depends on template resolution.
I cannot typecast base pointer since I do not know type because of
template. For example:
f()
{
base *a = new myclass<someclass>
f1(a);
}
void f1(base *a)
{
// I want to do this here.
a->callmethod(); // Would have worked if -> could return
myclass<someclass>*
}
Any suggestions?
Thanks,
Prakash
I have a template class as below:
template <class _T> class myclass{
public:
myclass(){ obj = new _T();}
_T* obj;
_T* operator->() (return obj;}
};
I need to keep all the myclass objects in a STL container such as
vector. But since every instantiation is a different type I cannot
have a vector or myclass.
So I derived myclass from a base class as below:
class base{
public:
base(){}
~base(){}
};
template class<_T> myclass : public base
Now I have a vector of base objects.
The problem is that I want to call -> operator. I cannot make it pure
virtual in base since the return type depends on template resolution.
I cannot typecast base pointer since I do not know type because of
template. For example:
f()
{
base *a = new myclass<someclass>
f1(a);
}
void f1(base *a)
{
// I want to do this here.
a->callmethod(); // Would have worked if -> could return
myclass<someclass>*
}
Any suggestions?
Thanks,
Prakash