i have a class shown below:
template <class TValue>
class ICData
{
private :
TValue value;
public:
inline ICData()
{
};
TValue get_value();
void set_value(TValue data);
};
template <class TValue>
TValue ICData<TValue>::get_value()
{
return value;
}
template <class TValue>
void ICData<TValue>::set_value(TValue _value)
{
value=_value;
}
i know how to make a pointer array by:
ICData <int> *ICArray[10];
ICArray[0]=new ICData<int>();
ICArray[1]=new ICData<int>();
but is there any way to make a pointer array using template ? like below:
template <class T>// iknow this code is WRONG
ICData <T> *ICArray[10];
ICArray[0]=new ICData<int>();
ICArray[1]=new ICData<float>();
thanks in advance.
If you wanted to store a pointer that could point to either a
ICData<int>or aICData<float>then those types would have to have a common base class and you could use that common base as the type to point to.As it stands the type
ICData<int>andICData<float>are not related so other than usingvoid *there is no solution to what you want to do that wouldn’t involve some ugly casts.