Question 7
Back to Exercise
The program below does not compile. Which statement correctly describes the problem?
#include <iostream>
class Meter {
double v_ = 1.5;
public:
double value() const;
};
double Meter::value() { return v_; }
int main() {
Meter m;
std::cout << m.value() << '\n';
return 0;
}
- A v_ must be an int
- B The definition omits const, so it does not match the declared double value() const – const is part of the member function's signature Correct
- C value must be virtual
- D Meter needs a constructor
Correct Answer: Option B
Write double Meter::value() const { … }. A const and a non-const version are different overloads.
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!