Topic: Can't convert function pointers where arguments are a subclass?
Author: Mike Austin <m.austin@ix.netcom.com>
Date: 2000/03/08 Raw View
I can see that one way would let RenderMessage act upon a Message and
cause problems, but what about the other way around? An base object
pointer is safe to operate on a derived class. As an example:
struct Message { };
struct RenderMsg : Message { };
class Visual {
public:
virtual void Render1( RenderMsg *msg ) { }
virtual void Render2( Message *msg ) { }
};
void (Visual::*method1)( Message* ) = &Visual::Render1;
void (Visual::*method2)( RenderMsg* ) = &Visual::Render2;
Neither of the last two lines compile.
Mike
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: Valentin Bonnard <Bonnard.V@wanadoo.fr>
Date: 2000/03/09 Raw View
Mike Austin wrote:
> I can see that one way would let RenderMessage act upon a Message and
> cause problems, but what about the other way around? An base object
> pointer is safe to operate on a derived class. As an example:
>
> struct Message { };
> struct RenderMsg : Message { };
>
> class Visual {
> public:
> virtual void Render2( Message *msg ) { }
> };
> void (Visual::*method2)( RenderMsg* ) = &Visual::Render2;
1) C++, unlike ML (or GNU C), does _not_ support closures;
C++ only supports simple pointer to function
2) RenderMsg* doesn't necessarily have the same representation
as Message* (real work is done when converting a derived
pointer to a base pointer)
--
Valentin Bonnard
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]