Question 6
Back to Exercise
The program below does not compile. Which statement correctly describes the problem?
#include <iostream>
struct Shape {
virtual double area() const = 0;
virtual ~Shape() = default;
};
struct Circle : Shape {
double r = 1;
double area() { return 3.14 * r * r; }
};
int main() {
Circle c;
std::cout << c.area() << '\n';
return 0;
}
- A r must be private
- B Circle::area() lacks const, so it does not override Shape::area() const; Circle is still abstract and cannot be created Correct
- C area must return float
- D Shape needs a constructor
Correct Answer: Option B
Writing override on Circle::area would have pointed straight at the missing const.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!