2011年10月25日

函数的返回值--返回变量和引用

摘要: --惯例:先上一段简单的代码#include <iostream.h>float temp; //定义一个全局变量float fn1(float r){ temp =(float) (r*r*3.14); return temp;}float& fn2(float r)//返回引用{ temp = (float)(r*r*3.14); return temp;}void main(){float a=fn1(5.0); ////float& b=fn1(5.0); //VC++ 6.0 error, (其他的编译器可能是warning)float c=fn2(5.0 阅读全文

posted @ 2011-10-25 18:57 沉沉-_- 阅读(2529) 评论(0) 推荐(0) 编辑

类的默认构造函数--为何使用引用以及什么时候显式的给出

摘要: 先上一段简单代码:#include<iostream>using namespace std;class test{public:test(){cout<<"默认构造函数"<<endl;}~test(){cout<<"析构函数"<<endl;}void fun1(test & t){cout<<"fun1 called"<<endl;}void fun2(test t){cout<<"fun2 called"&l 阅读全文

posted @ 2011-10-25 12:32 沉沉-_- 阅读(392) 评论(0) 推荐(1) 编辑

导航