Afficher un message
Vieux 16/10/2007, 15h09   #1
Wayne Shu
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut A problem about virtual function?

Hi everyone,

Today I meet a problem about virtual function. Consider the
following little program.

#include <iostream>

class base
{
int i;
public:
virtual void print() { std::cout << "base" << std::endl; }
virtual ~base() {}
};

class derived : public base
{
public:
virtual void print() { std::cout << "derived" << std::endl; }
};

int main()
{
base b;
b::~base();

new (&b) derived;

(&b)->print(); // (1)
base *p = &b;
p->print();

return 0;
}

I have try the VC2005 Express Edition and GCC 3.4.2
and the result is :
base
derived

Why (1) statement print "base"?

thanks

Best Regards.

  Réponse avec citation
 
Page generated in 0,05808 seconds with 9 queries