/* 时间:2020年5月11日19:27:38 地点:大石板 功能:数组元素是每一个对象*/ #include<iostream> using namespace std; class Complex { public: Complex();//声明构造函数1 Complex(int n);//声明构造函数2 }; //定义构造函数1 Complex::Complex() { cout<< "构造函数1" << endl; } //定义构造函数2 Complex::Complex(int n) { cout << "构造函数2" << endl; } int main() { //在栈上创建对象 cout << "step1" << endl; Complex arry1[2]; cout << "step2" << endl; Complex arry2[2] = { 1,2 }; cout << "step3" << endl; Complex(); //在堆上创建对象,注意使用delete释放内存 Complex* pComplex = new Complex; Complex arry3[2] = { 1, }; delete pComplex; return 0; }
原文:https://www.cnblogs.com/qq1480040000/p/12871279.html