Re: downcasting template class with paramaterised parent
<jason.saunders@gmail.com> wrote in message
news:1153842625.988982.183970@h48g2000cwc.googlegroups.com...
I have a situation where I have a number of MFC derived
classes. For
example two classes are;
class MyEdit : public CEdit
and
class MyButton : public CButton
I want to derive MyEdit and MyButton from a common class
but to retain
the MFC inheritance.
Therefore I introduced a template class which has the
parent as a
parameter, e.g.;
template <class PARENT>
class MyControl : public PARENT
I now want to implement some common functionality in the
MyControl
class, e.g.;
template <class PARENT>
class MyControl : public PARENT
{
...
Common()
{
// Do something
}
...
}
I want to be able to call the Common method without
knowing the runtime
type of the object. I have a pointer to a CWnd which can
be downcast
to a MyButton or MyEdit.
How do I cast the CWnd pointer appropriately to call the
Common method?
You cannot, since MyControl is not a type. So there is no
type to downcast to. MyControl<T> will become a type when
it's instantiated.