Question 9
Back to Exercise
The program below does not compile. Which statement correctly describes the problem?
#include <iostream>
class Settings {
public:
static inline int volume = 40;
};
void louder() {
volume += 10;
}
int main() {
louder();
std::cout << Settings::volume << '\n';
return 0;
}
- A volume must be const
- B Outside the class, a static member must be named with its class: Settings::volume; plain volume is undeclared in louder() Correct
- C louder must be a friend
- D static inline is not allowed
Correct Answer: Option B
Only code inside the class (its member functions) can use the unqualified name.
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!