⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 temp_obj.cpp

📁 C++中临时变量的例子,说明C++是如何使用临时变量以及如何销毁临时变量的
💻 CPP
字号:
// temp_obj.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#include "temp.h"
using namespace std;
class A
{
public:
	A(int i):num(i){cout<<"A is constructed with "<<i<<endl;};
	~A(){cout<<"A is destructed"<<endl;};
	
	void show()
	{
		cout<<"A.num is "<<num<<endl;
	}
	int inc()
	{
		return ++num;
	}
	int dec();
private:
	int num;
};
A f(A a)
{
	a.inc();
	a.show();
	return a;
}
int A::dec()
{
	return --num;
}
int main(int argc, char* argv[])
{
	A  test(9);
	A&  result=f(test);
	result.show();
	return 0;
}



/*
A(A& a)
	{
		this->num=a.num;
		cout<<"A is constructed by copy"<<endl;
	}
*/


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -