#include <iostream> using namespace std; class Anew { public: int a; Anew() {} }; Built class { public: int a; Built (): a (100) {} }; class Cnew { public: int a; }; int main(int argc, char *argv[]) { Anew tmp1; Anew* tmp2 = new Anew; Anew* tmp3 = new Anew(); cout << tmp1.a<<endl; cout << tmp2->a<<endl; cout << tmp3->a<<endl; Built tmp11; * = New built tmp22 built; * Built tmp33 = new built () cout << tmp11.a<<endl; cout << tmp22->a<<endl; cout << tmp33->a<<endl; Cnew tmp111; Cnew* tmp222 = new Cnew; Cnew* tmp333 = new Cnew(); cout << tmp111.a<<endl; cout << tmp222->a<<endl; cout << tmp333->a<<endl; return 0; }
g++ 8.1.0
Output:
0
-1163005939
-1163005939
100
100
100
2046
-1163005939
0
Anew manually write a constructor
Bnew manually write a constructor to initialize and have a value
Cnew compiler that comes with the constructor