lundi 13 mars 2017

Why it is not allowed to create an object of the abstract class in C++

I know that whenever I set my virtual function to 0, I will make it as an abstract class. Suppose I have a function in my abstract class:

int add (const BaseClass &other) { 
return (sum() - other.sum()); }

but since I cannot create an object for the base class then I have to call function add using another object, like this:

OtherClass o;
o.add(o);

but after that I will be using the function sum from the derived class minus the sum from also the derived class. So how to call the function add using an object of Base class so that I want the first call of sum to be from the Base class. Thanks in advance!

Aucun commentaire:

Enregistrer un commentaire