有关用引用返回值中的问题??????????????、
#include<iostream.h>float temp;
float fn1(float r)
{
temp=r*r*3.14;
return temp;
}
float& fn2(float r)
{
temp=r*r*3.14;
return temp;
}
int main()
{
float a=fn1(5.0);
float& b=fn1(5.0);
float c=fn2(5.0);
float& d=fn2(5.0);
cout<<a<<endl;
cout<<b<<endl;
cout<<c<<endl;
cout<<d<<endl;
}
VC6.0提示:--------------------Configuration: pp193 - Win32 Debug--------------------
Compiling...
ppp193.cpp
F:\C++文件\pp193\ppp193.cpp(7) : warning C4244: '=' : conversion from 'double' to 'float', possible loss of data
F:\C++文件\pp193\ppp193.cpp(13) : warning C4244: '=' : conversion from 'double' to 'float', possible loss of data
F:\C++文件\pp193\ppp193.cpp(20) : error C2440: 'initializing' : cannot convert from 'float' to 'float &'
A reference that is not to 'const' cannot be bound to a non-lvalue
F:\C++文件\pp193\ppp193.cpp(27) : warning C4508: 'main' : function should return a value; 'void' return type assumed
执行 cl.exe 时出错.
ppp193.obj - 1 error(s), 0 warning(s)
求大神们分析?????????????????????