ERROR object of abstract class type is not allowed

Sep 27, 2013 at 5:35pm
Complete
Last edited on Sep 27, 2013 at 6:06pm
Sep 27, 2013 at 5:55pm
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
Sep 27, 2013 at 6:06pm
Thanks, I think i'm heading on the right track now.
Sep 27, 2013 at 6:20pm

Complete


if you understand my next words: don't ever do that again.
Sep 27, 2013 at 6:22pm
I've done it all the time...Why is it a problem?
Last edited on Sep 27, 2013 at 6:27pm
Sep 27, 2013 at 6:36pm
same question: is it a problem to keep it that way?
Sep 27, 2013 at 6:42pm
So what you're saying is that it isn't a problem. And I have my reasons for removing it.
Sep 27, 2013 at 6:43pm
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 Sep 27, 2013 at 6:43pm
Sep 27, 2013 at 6:47pm
Thank you, Chervil for actually explaining why and not being rude. I won't remove it anymore.
Topic archived. No new replies allowed.