形参初始化顺序从右向左,析构与构造顺序相反
由于是栈空间所以,先构造后析构,后构造先析构。
测试代码:
#include <iostream>
using namespace std;
class Test
{
public:
Test(int);
Test(Test&);
~Test();
private:
int a;
};
Test::Test(int i)
{
a = i;
cout << "constructing " << a << endl;
}
Test::Test(Test& test)
{
a = test.a;
cout << "copying " << a << endl;
}
Test::~Test()
{
cout << "destructing " << a << endl;
}
void outPut(Test test1, Test test2);
int main() {
Test* a = new Test(3);
Test test1(1);
Test test2(2);
outPut(test1, test2);
system("pause");
return 0;
}
void outPut(Test test1, Test test2) {
}