I am trying to create a very basic class with a default constructor:
class Point {
public:
Point() = default;//con 1
explicit Point(double x): x_axis(x), y_axis(0){}//con 2
Point(const Point &other) = default;
~Point() = default;
private:
double x_axis;
double y_axis;
}
When I try to use the default constructor in the main() function, it generates a random junk value for x_axis:
Point p1;//generates random value
Point p2{};//works as intended
Why is that? When I use the other constructor (con 2) like so:
explicit Point(double x = 0): x_axis(x), y_axis(0){}
Both of them work as intended.
- why, in the first try with no brackets, does it generate a random value, but
{}worked, but in the second try they both work? - what is calling the default constructor with
{}?