I was trying out the following sample code from Scotty Meyers:
Effective C++ book:
#include <iostream>
class B {
public:
virtual void f() const { std::cout << "B::f()" << std::endl; }
};
class D : public B {
public:
virtual void f() { std::cout << "D::f()" << std::endl; }
};
int main()
{
D dx;
B *pb = &dx;
pb->f(); // will call B::f()
return 0;
}
He says according to the standards this should be a compiler error but
some compilers allow this to work. I found Visual Studio and g++ 3.2
allow this.
I would like to know if this is true, if not what maybe the philosophy
behind allowing this ambigious behavior?
Effective C++ book:
#include <iostream>
class B {
public:
virtual void f() const { std::cout << "B::f()" << std::endl; }
};
class D : public B {
public:
virtual void f() { std::cout << "D::f()" << std::endl; }
};
int main()
{
D dx;
B *pb = &dx;
pb->f(); // will call B::f()
return 0;
}
He says according to the standards this should be a compiler error but
some compilers allow this to work. I found Visual Studio and g++ 3.2
allow this.
I would like to know if this is true, if not what maybe the philosophy
behind allowing this ambigious behavior?
Comment