AI Features

Discussion: A Strong Point

Execute the code to understand the output and gain insights into strong typing and implicit conversions.

Run the code

Now, it’s time to execute the code and observe the output.

C++ 17
#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_;
}

Strong typing

The Player struct has a points_ member to keep track of the player’s points. Instead of using a fundamental type like int for this, we use a custom type Points. This technique is often called strong typing and can make the code easier to read and avoid bugs. ...

Ask