Question Down-cast with as type a template-parameter

ad.ministrator

New member
Joined
Dec 21, 2009
Messages
1
Programming Experience
10+
I have a base class B and serveral derived classes D1, D2, D3 etc.

I created a template class T like this:

Public Class T(Of X)
Public Function GetDerived(Byref Base As B) as X
Return CType(Base, X)
End Function
End Class

I use the template class with D1 or D2 or, any other derived class of B, as X

I get an error because the computer doesn't know that X is derived from B: D1 or D2 or D3 or D4.

In C++ this is allowed. What do I have to do? I suppose the Type as parameter of CType cant be a template parameter. Am I right?
 
Back
Top