| 1 |
char s[12]; cin.get(s,12); //cin.get()以'\n'为结束符 |
| 2 |
#include <iostream>
using namespace std;
class box
{
public:
box(int x){i=x;}
void show()const{cout<<i<<endl;}
~box()
{
cout<<"执行析构函数..."<<endl;
}
private:
int i;
};
box &f()//返回引用
{
box *a=new box(10);//实例一个对象
return *a;//返回对象
}
int main()
{
box &r=f();//接收引用
r.show();
box *p=&r;//引用地址传入p
delete p;//最后删除堆对象
return 0;
}
|

浙公网安备 33010602011771号