Question 2
Back to Exercise
The program below does not compile. Which statement correctly describes the problem?
#include <iostream>
class Version {
public:
static int major() const { return 2; }
};
int main() {
std::cout << Version::major() << '\n';
return 0;
}
- A major is a keyword
- B A static member function cannot be const: const qualifies the object pointed to by this, and a static function has no this Correct
- C static functions must be private
- D Version needs a constructor
Correct Answer: Option B
Drop const: static int major() { return 2; }. It cannot modify any object anyway.
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!