ta0kira
2003-08-28 00:08:14 UTC
I would like to make a function in an abstract class virtual, but
I can't because of a compiler error. Here is what I would like
to do:
template <class Type> struct APointer
{
template <class Type2> Type2 *PGetAs() {} //Want this virtual
};
template <class Type> struct PointerDef :
virtual public APointer <Type>
{
Type *Point;
template <class Type2> Type2 *PGetAs()
{return reinterpret_cast <Type2*> (Point);}
};
template <class Type> struct PMirror :
virtual public APointer <Type>
{
PointerDef <Type> *Original; //Want to make this 'APointer'
template <class Type2> Type2 *PGetAs()
{return Original->PGetAs <Type2*> ();}
//If 'Original' is APointer, I get access errors trying to use
//the resulting pointer
};
I would add 'Point' to APointer and then define the function body
of 'PGetAs()' in APointer, but I do not want the wasted pointer
in PMirror, and I want to re-define the function there as well.
Is there a way to use allow a template function to be re-defined
and accessed thru an abstract pointer? Thanks.
ta0kira
I can't because of a compiler error. Here is what I would like
to do:
template <class Type> struct APointer
{
template <class Type2> Type2 *PGetAs() {} //Want this virtual
};
template <class Type> struct PointerDef :
virtual public APointer <Type>
{
Type *Point;
template <class Type2> Type2 *PGetAs()
{return reinterpret_cast <Type2*> (Point);}
};
template <class Type> struct PMirror :
virtual public APointer <Type>
{
PointerDef <Type> *Original; //Want to make this 'APointer'
template <class Type2> Type2 *PGetAs()
{return Original->PGetAs <Type2*> ();}
//If 'Original' is APointer, I get access errors trying to use
//the resulting pointer
};
I would add 'Point' to APointer and then define the function body
of 'PGetAs()' in APointer, but I do not want the wasted pointer
in PMirror, and I want to re-define the function there as well.
Is there a way to use allow a template function to be re-defined
and accessed thru an abstract pointer? Thanks.
ta0kira