consider ...
#include <stdio.h>
class B
{
public:
B()
{
puts("B::B()");
Method();
}
~B()
{
}
void Foo()
{
puts("B::Foo()");
Method();
}
virtual void Method()
{
puts("B::Method()");
}
};
class A : public B
{
public:
A() : B()
{
puts("A::A()");
}
~A()
{
}
void Method()
{
puts("A::Method()");
}
};
int main()
{
A k;
k.Foo();
return 0;
}
Now what is happening here is when A's constructor is called, it calls B's constructor which calls virtual Method().
When you call Foo (function from B) it again calls Method
the problem is, how come the constructor ALWAYS accesses the virtual method when the latter class overrides it, yet foo doesnt (when called from main... if called in constructor it again calls the overriden function)?