Reputation: 8015
Will the following program cause any problem during compiling and execution process?
class A{
public: virtual void foo(){}
};
class B:public A{};
int main(){
B b;
b.foo();
}
Upvotes: 0
Views: 145
Reputation: 349
There will be no problems compiling or running this program.
virtual
functions can be overridden, but they don't have to be. If an object's class does not implement the virtual function, then the superclass will be checked for an implementation.
Upvotes: 1
Reputation: 11858
Maybe, I'm guessing, they were testing if you knew the difference between virtual and abstract?
Upvotes: 1
Reputation: 9891
Why would it have a problem? You're calling a virtual function that IS defined on the parent class. B inherits it.
Upvotes: 0