M
Maurice Termeer
Hi, suppose i've got a nice tree of polymorphic types, like an abstract
base class shape and some subclasses like circle, traingle and square.
Now i also happen to have a list of pointers to triangles (so of type
list<triangle *>) and i want to pass this list to a function that
accepts a list of shapes (so the parameter is of type list<shape *>).
How can I cast the triangle list to a list of shapes?
The normal cast operators don't work, then the compiler says something like:
'reinterpret_cast' : cannot convert from 'std::list<_Ty>' to
std::list<_Ty>' with [ _Ty=triangle * ] and [ _Ty=shape * ] Conversion
requires a constructor or user-defined-conversion operator, which can't
be used by const_cast or reinterpret_cast
or
'static_cast' : cannot convert from 'std::list<_Ty>' to 'std::list<_Ty>'
with [ _Ty=triangle * ] and [ _Ty=shape * ] No constructor could
take the source type, or constructor overload resolution was ambiguous
what does this mean, and more important, how do I solve this?
Maurice Termeer
base class shape and some subclasses like circle, traingle and square.
Now i also happen to have a list of pointers to triangles (so of type
list<triangle *>) and i want to pass this list to a function that
accepts a list of shapes (so the parameter is of type list<shape *>).
How can I cast the triangle list to a list of shapes?
The normal cast operators don't work, then the compiler says something like:
'reinterpret_cast' : cannot convert from 'std::list<_Ty>' to
std::list<_Ty>' with [ _Ty=triangle * ] and [ _Ty=shape * ] Conversion
requires a constructor or user-defined-conversion operator, which can't
be used by const_cast or reinterpret_cast
or
'static_cast' : cannot convert from 'std::list<_Ty>' to 'std::list<_Ty>'
with [ _Ty=triangle * ] and [ _Ty=shape * ] No constructor could
take the source type, or constructor overload resolution was ambiguous
what does this mean, and more important, how do I solve this?
Maurice Termeer