U
ujjwal bhoota
Hi,
Can any one explain me the behaviour of following program.
#include <iostream>
using namespace std;
class A {
public:
A() {
this->Foo();
}
virtual void Foo() {
cout << "A::Foo()" << endl;
}
};
class B : public A {
public:
B() {
this->Foo();
}
virtual void Foo() {
cout << "B::Foo()" << endl;
}
};
int main(int, char**)
{
B objectB;
return 0;
}
The output is
A::Foo()
B::Foo()
should not it be
B::Foo()
B::Foo()
as B::Foo() has been declared to be virtual
thanks and regards
UJJWAL
Can any one explain me the behaviour of following program.
#include <iostream>
using namespace std;
class A {
public:
A() {
this->Foo();
}
virtual void Foo() {
cout << "A::Foo()" << endl;
}
};
class B : public A {
public:
B() {
this->Foo();
}
virtual void Foo() {
cout << "B::Foo()" << endl;
}
};
int main(int, char**)
{
B objectB;
return 0;
}
The output is
A::Foo()
B::Foo()
should not it be
B::Foo()
B::Foo()
as B::Foo() has been declared to be virtual
thanks and regards
UJJWAL