On Sat, 07 Aug 2004 23:36:57 GMT, none <> wrote:
>Hi,
>I have a base class with a pointer-to-member function
>variable. Then I have a derived class that needs to
>use that variable to call a member function (with the
>same arguments and return value type) in the derived
>class. I know in Visual C++ you can just cast the
>pointer to member function of the derived class to
>that of the base class and it will work, but is this
>legal by C++ standards?
You shouldn't need a cast, if I am reading the standard correctly. If
the member is accessible (i.e. public or protected), then you should
be able to use it directly.
If a cast is necessary, you must cast the base class pointer to that
of the derived class according to 4.11.2 of the standard. The base
class may not be inaccessible, nor ambiguous, nor virtual.
There is a footnote here which reads:
"The rule [...] appears inverted compared to the rule for pointers to
objects [...] This inversion is necessary to ensure type safety [...]"
--
Bob Hairgrove