less than 1 minute read

2024-08-26 后记:已经不需要太 care 了,现在已经很少用 new


#include <iostream>
using namespace std;

class Tango {
public:
	int i;
};

class Papa {
public:
	int i;
	Papa() {
	
	}
};

int main() {
	Tango tango;
	Tango* ptango = new Tango;
	Tango* ptango2 = new Tango();
	
	cout << tango.i << endl;
	cout << ptango->i << endl;
	cout << ptango2->i << endl;
	
	Papa papa;
	Papa* ppapa = new Papa;
	Papa* ppapa2 = new Papa();
	
	cout << papa.i << endl;
	cout << ppapa->i << endl;
	cout << ppapa2->i << endl;
}

// output:
/*
	-1
	6324112
	0
	6317616
	6319120
	6055888
*/

Categories:

Updated:

Comments