~$ 存档

  博客园 :: 首页 :: 新随笔 :: 联系 :: 订阅 :: 管理 ::
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;
}

  

   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
posted on 2017-01-15 21:50  LuoTian  阅读(96)  评论(0)    收藏  举报