Newsgroups: alt.comp.lang.learn.c-c++, comp.lang.c++
From: Garrett Hartshaw <gharts...@gmail.com>
Date: Fri, 07 Jan 2011 17:47:12 -0500
Local: Fri, Jan 7 2011 5:47 pm
Subject: Re: Frasncis Glassboro wrote.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1 On 01/07/2011 02:06 PM, Paul wrote: > "James Kanze" <james.ka...@gmail.com> wrote in message >> [...] >>> > &ClassName::functionName >>> > Concretely: >>> > struct C { void f(); }; >>> >> b) what happens if this member function is virtual? >>> > It works correctly. That's why pointer to member functions are >>> What would your pointer point to ? >> That's the compiler writers problem, not mine:-). > It certainly is a problem for the compiler, and perhaps the program too. >>> You cannot do this with virtual functions and you are wrong >> It does work, and I've done it. More than once. > It simply can't be done as the concept of virtual functions only lives class C1 { }; class C2 : public C1 { public: virtual void f() { std::cout << "C2::f" << std::endl; } }; int main () { void (C1::*p)() = &C1::f; //create a pointer to a member function C1 a; //create a object of type C1 (a.*p)(); //call the member function pointed to return 0; } This code prints the following. C1::f iQIcBAEBAgAGBQJNJ5fwAAoJEO0SzzQOdchN7x0P/j9jO/ptm/i8ir1LzUI9WhpN You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
| ||||||||||||||