This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

weird stuff with pointers to members, casts


# cat mp.cc
#include <iostream>

struct C;

typedef void (C::* VMCP) ();

struct C {
        static int counter;

        VMCP f () {
                counter++;
                cout << this << "->f ()" << endl;
                return (VMCP)&C::f;
        }
};

int C::counter (0);

int
main () {
        C c;
        VMCP (C::* p1) ();

        p1 = (VMCP (C::*) ()) c.f ();
        if (c.counter != 1) {
                cerr << "C::f called " << c.counter << " times" << endl;
                return 1;
        }
}
# ./mp
0x80479cb->f ()
0x80479cb->f ()
0x80479cb->f ()
0x80479cb->f ()
C::f called 4 times
#

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]