【C\C++】函数传参中结构体构造析构顺序的探究

【C\C++】函数传参中结构体构造析构顺序的探究

[by_041]
  • 参考以下程序,通过观察输出结果得出结论、、
#include<bits/stdc++.h>

using namespace std;

struct test_1
{
	test_1(){cout<<"create\t1"<<endl;}
	~test_1(){cout<<"free\t1"<<endl;}
	test_1 operator++(){cout<<"op\t1"<<endl;return *this;}
}t1;

struct test_2
{
	test_2(){cout<<"create\t2"<<endl;}
	~test_2(){cout<<"free\t2"<<endl;}
	test_2 operator++(){cout<<"op\t2"<<endl;return *this;}
}t2;

struct test_3
{
	test_3(){cout<<"create\t3"<<endl;}
	~test_3(){cout<<"free\t3"<<endl;}
	test_3 operator++(){cout<<"op\t3"<<endl;return *this;}
}t3;


void kong(test_1 a,test_2 b,test_3 c)
{
	cout<<"in kong( )"<<endl;
	return;
}

int main()
{
	kong(++t1,++t2,++t3);
	return 0;
}

版权声明:本文为qq_42710619原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。