Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion Frasncis Glassboro wrote.
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
stan  
View profile  
 More options Jan 7 2011, 9:28 pm
Newsgroups: alt.comp.lang.learn.c-c++, comp.lang.c++
From: stan <smo...@exis.net>
Date: Fri, 7 Jan 2011 21:28:08 -0500
Local: Fri, Jan 7 2011 9:28 pm
Subject: Re: Frasncis Glassboro wrote.

Garrett Hartshaw wrote:
> On 01/07/2011 02:06 PM, Paul wrote:

<snip>

>> It simply can't be done as the concept of virtual functions only lives
>> in the world of objects.
>> Please show some basic code. I guarantee you cannot.

> #include <iostream>

> class C1 {
> public:
>     virtual void f() {
>         std::cout << "C1::f" << std::endl;
>     }
> };

> 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
>   C1 * b;                  //create a object of type pointer to C1
>   b = new C2();                    //allocate a object of type C2

>   (a.*p)();                        //call the member function pointed to
>                                 //by p, with &a as this
>   (b->*p)();                    //call the member function pointed to
>                                 //by p (virtually), with b as this

>   return 0;
> }

> This code prints the following.

> C1::f
> C2::f

Did you hear that? Sounded like "I'm mmeelllllllttttting"

 
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.