| initialization/init2.cc - Default initialization. | Lecture 2 - slide 26 : 29 Program 1 |
// Shows default initialization with {}
#include <iostream>
class Point {
public:
double x, y;
Point(double x, double y): x(x), y(y) {}
Point(): x(1.1), y(2.2){}
};
int f(){
int i{}; // i becomes 0, the default int value
double d{}; // d becomes 0.0, the default double value
char *c{}; // c becomes the null pointer, the default pointer value
Point p{}; // p becomes (1.1, 2.2), the default Point object - using the default constructor
std::cout << "i: " << i << std::endl; // 0
std::cout << "d: " << d << std::endl; // 0
std::cout << std::hex << "c: " << (unsigned int)c << std::endl; // 0
std::cout << "p: " << p.x << ", " << p.y << std::endl; // 1.1, 1.2
}
int main(){
f();
}