Puzzle 17A Strong Point

 #include <iostream>
 
 struct​ Points
 {
  Points(​int​ value) : value_(value) {}
 int​ value_;
 };
 
 struct​ Player
 {
 explicit​ Player(Points points) : points_(points) {}
  Points points_;
 };
 
 int​ ​main​()
 {
  Player player(3);
  std::cout << player.points_.value_;
 }

Guess the Output

images/aside-icons/important.png

Try to guess what the output is before moving to the next page.

images/hline.png

The program displays the following output:

 3

Discussion

The Player struct has a member points_ to keep track of the player’s points. Instead ...

Get C++ Brain Teasers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.