📄 demo_copy_constructor_6(临时对象).cpp
字号:
//************************************************
// 函数返回值对象是临时对象,不能赋值给对象的引用。
//************************************************
# include <iostream.h>
# include <string.h>
class Student
{
public:
Student(char* pName="No Name")
{
cout<<"Constructing new student "<<pName<<endl;
strcpy(name,pName);
}
~Student()
{
cout<<"Destructing "<<name<<endl;
}
protected:
char name[20];
};
Student fn()
{
Student ms("Jenny");
cout<<"In function fn()"<<endl;
return ms;
}
void main()
{
Student& refs=fn(); //临时对象
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -