I've derived a template class from non-template base

```
struct CBaseList {
  virtual size_t Size() = 0;
};

template <class T>
struct CPointList : public BaseList { 
  virtual size_t Size() { return mData.size(); }
  std::vector <T> mData;
};

// Ok, now I can create various instances
CBaseList * lst1 = new CPointList<float> ();
CBaseList * lst2 = new CPointList<double> ();

```

But how can I copy/assign values between different instances? For example 

```
template <class T1, class T2>
void CopyVec( const T1 & src, T2 & dst )
{
  dst.resize(src.size());
  for (size_t i = 0; i < src.size(); ++i)
   dst[i] = src[i];    
}

void CopyList( const CBaseList * src, CBaseList * dst )
{
 // How to call CopyVec ?
}

```

If I cast CBaseList(s) to any derived class, then I've a big ugly "switch". Are there better solutions?

Thanks
Igor

---

thiton

Thanks for your replies. I realize any compiler should see/have types to generate code from template - no other way. But how to implement it compactly and once, without replicating for any needed template function? I'm thinking about a sketch like:

```
// caller
theWrapper(lst1, lst2)->mInstance().DoCopy(lst1, lst2, num);

// mInstance type
template <class T1, class T2>
struct CWrapInstance {
 void DoCopy( CBaseList * lst1, CBaseList * lst2, size_t num ) 
 {
  // cast types and call original template
  Copy(((T1 *) lst1)->mData, ((T2 *) lst2)->mData, num); 
 }
}; 

```

So for every new template I need to add only a small method to CWrapInstance. But how to design "theWrapper" ?

Thx for your understanding.
Igor