ERROR object of abstract class type is not allowed

Complete
Last edited on
closed account (o3hC5Di1)
Hi there,

In the pet header file:

virtual string getLifespan() const = 0;

A base class which provides functionality, but also defines pure virtual functions for its derived classes to implement is called an abstract base class. You cannot create instances of such classes, because you have not defined behaviour for getLifeSpan(). If you would call that function on a Pet object, it would not know what to do.

You can either not create Pet objects if it is intended as a base class only, or you can provide a basic functionality for getLifeSpan(), which could be overloaded by derived classes.

Hope that helps.

All the best,
NwN
Thanks, I think i'm heading on the right track now.

Complete


if you understand my next words: don't ever do that again.
I've done it all the time...Why is it a problem?
Last edited on
same question: is it a problem to keep it that way?
So what you're saying is that it isn't a problem. And I have my reasons for removing it.
The argument goes, these forum threads are useful for others to read. By removing an important part of the content, it prevents the thread from being of any use to anyone.
Last edited on
Thank you, Chervil for actually explaining why and not being rude. I won't remove it anymore.
Topic archived. No new replies allowed.