Question 10
Back to Exercise
The program below does not compile. Which statement correctly describes the problem?
#include <iostream>
class List {
struct Node {
int value;
Node* next;
};
public:
int size() const { return 0; }
};
int main() {
List::Node n{5, nullptr};
std::cout << n.value << '\n';
return 0;
}
- A Node must have a constructor
- B Node is declared in the private section of List, so code outside List cannot name it Correct
- C next must be a reference
- D List must be a struct
Correct Answer: Option B
Private nested classes are implementation details. Make Node public if users really need it.
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!