question

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



How could this (included) very short code work?
It isn't a NOT SAFE conversion that made inside void fun?

How can the A pointer know about the B's member f() ?

I'm using gcc 4.8.2 on a Linux Fedora 19 system.

Thanks for your help.

G. Servizi

Code follows:

# include <iostream>
using namespace std;

 class A {/*omissis*/};
 class B : public A
  {/*omissis*/
   public:
   void f( ){cout<<"bye\n";}};

 void fun(A *a)
 {
 B *b = static_cast<B *>(a);
 b -> f( );
 }

 int main( )
 {
 A *a = new A;
 fun(a);
 }




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux