Question 1
Back to Exercise
The program below does not compile. Which statement correctly describes the problem?
#include <iostream>
class Order {
double amount_ = 499;
public:
static double with_tax() { return amount_ * 1.18; }
};
int main() {
std::cout << Order::with_tax() << '\n';
return 0;
}
- A 1.18 must be a constant
- B with_tax is static, so there is no object whose amount_ it could read; make it a non-static member or pass an Order Correct
- C amount_ must be public
- D static functions cannot return double
Correct Answer: Option B
Non-static members belong to objects; a static member function has none.
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!