You have got to be kidding! The error says that calArea needs to return a value. The definition of calArea is:
double Shape::calArea()
{ }
How is that confusing? All you need to do is return a value:
double Shape::calArea()
{
return 0;
}
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
>In the Shape class this function has an ‘empty’ implementation, which is over-ridden in the derived classes
In Shape calArea needs no implementation because pure virtual member functions make a class abstract. In the derived class Circle, it must have an implementation or the class inherits abstract behavior from Shape, and can't be instantiated. I agree that the wording is vague. I've found that it's better to make a clear distinction between function declarations and function definitions, then stick to that terminology.
If you define a pure virtual function then it still must follow the rules, such as returning a value.
>By deleting the function body from the virtual function it works!
Yes, because it doesn't need a definition. Only a declaration that the derived classes redefine.
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401