I hav a base class which is abstract. I am inheritting a new class from the abstract base which i could not instantiate an object. The reason the compiler tells is that
cannot allocate an object of abstract type
Is there any way to overcome this.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This indicates you’ve not implemented all the pure
virtualfunctions in the derived class. So first, implement all the pure virtual functions, then create instance of this class.You cannot create instances of class which has even a single pure
virtualfunction!Remember, pure virtual functions are those which are assigned with zero (C++ Virtual/Pure Virtual Explained), as
Here only
g()is pure virtual function! This makessamplean abstract class, and if the derived class doesn’t defineg(), it would also become an abstract class. You cannot create instance of any of these class, as both of them are abstract!