...

/

Solution: Detect Narrowing Conversion

Solution: Detect Narrowing Conversion

The solution to the challenge, 'Exercise: Detect Narrowing Conversion'.

We'll cover the following...

Solution

Press + to interact
#include <iostream>
struct Point2D {
int x;
int y;
};
class Point3D {
public:
int x;
int y = 1;
int z = 2;
};
int main() {
std::cout << '\n';
Point2D point2D{.x = 1, .y = 2.5};
Point3D point3D{.x = 1, .y = 2, .z = 3.5f};
std::cout << "point2D: " << point2D.x << " " << point2D.y << " ";
std::cout << "point3D: " << point3D.x << " " << point3D.y << " "
<< point3D.z << '\n';
std::cout << '\n';
}
...