Open In App

C++ | Virtual Functions | Question 5

Last Updated : 28 Jun, 2021
Like Article
Like
Save
Share
Report




#include<iostream>
using namespace std;
  
class Base
{
public:
    virtual void show() = 0;
};
  
int main(void)
{
    Base b;
    Base *bp;
    return 0;
}


(A) There are compiler errors in lines “Base b;” and “Base bp;”
(B) There is compiler error in line “Base b;”
(C) There is compiler error in line “Base bp;”
(D) No compiler Error


Answer: (B)

Explanation: Since Base has a pure virtual function, it becomes an abstract class and an instance of it cannot be created.

So there is an error in line “Base b”.

Note that there is no error in line “Base *bp;”. We can have pointers or references of abstract classes.

Quiz of this Question


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads