【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;
}

猜你喜欢

转载自blog.csdn.net/qq_42710619/article/details/115324180