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();
}
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();
}
Why would it have a problem? You're calling a virtual function that IS defined on the parent class. B inherits it.
Maybe, I'm guessing, they were testing if you knew the difference between virtual and abstract?
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.