This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Problems invoking a member function through pointers.
- To: egcs at egcs dot cygnus dot com
- Subject: Problems invoking a member function through pointers.
- From: <adriang at adriang dot ce dot mediaone dot net>
- Date: Mon, 21 Dec 1998 23:08:06 -0600 (EST)
In the following code I would expect the output to be:
Base::M1
Base::M1
Base::M2
Base::M2
To my surprise, the last line of the output says
Derived::M2
Does the standard mandate this behaviour?
I've tried with both Microsoft compiler and egcs.
thanx
#include <iostream>
class Interface
{
public:
virtual void M1(void) = 0;
virtual void M2(void) = 0;
};
class Base : public Interface
{
public:
void M1(void){ std::cout << "Base::M1\n"; }
void M2(void){ std::cout << "Base::M2\n"; }
void Check(void);
};
class Derived1 : public Base
{
public:
void M2(void){ std::cout << "Derived::M2\n"; }
};
void Base::Check(void)
{
void (Base::*pfn1)(void) = &Base::M1;
Base::M1();
(this ->* pfn1)();
void (Base::*pfn2)(void) = &Base::M2;
Base::M2();
(this ->* pfn2)();
}
void main(void)
{
Derived1 d1;
d1.Check();
}