class A{
virtualvoid func(){
std::cout<<"I'm A\n";
}
void func2(){
func(); // Is there any difference from this.func();?
}
};
class B : public A{
void func(){
std::cout<<"I'm B\n";
}
};
If I store B as an A pointer and call func2() from it, what will it print? Does it change if I change func2 in A (like in the comment)?
1 2
A* b = new B();
b->func2(); // What will this print?
@cire Sorry, if I wasn't extremely clear. I was implying that the call would be from an object, but in my case it would be from a pointer stored as parent class pointer.
In the second code snippet in the OP, "I'm B\n" will be printed since the function is virtual. If the function weren't virtual, "I'm A\n" would be printed. The first snippet with func2 is still nonsensical.