afsfop:
第一个函数:Attempting to return a reference to local variable
就算编译通过了,也得不到答案的
可以用:
const int & square(int i)
{ static int t=i*i;
return t;
}
但没有这种必要
but both of your functions are wrong, because 't' and the result of 'i*i' are temporay objects. when you quit from the functions, their addresses are released automatically for other uses, which means the objects disappear. so you can not have references for these non-existant objects.