被reference搞晕了# Programming - 葵花宝典
d*n
1 楼
以下2种case,哪些对?
// use template for generality
case 1
T fn(T & in)
{
T &value = in; //two references point to one object (ok?)
// do something
return value; //is a reference returned?
}
case 2
T &fn(T & in)
{
T &value = in;
// do something
return value; //is a reference returned? what difference from the case 1?
}
My purpose: if class T is big, it's efficient to pass/return its reference.
The above 2 cases will do?
// use template for generality
case 1
T fn(T & in)
{
T &value = in; //two references point to one object (ok?)
// do something
return value; //is a reference returned?
}
case 2
T &fn(T & in)
{
T &value = in;
// do something
return value; //is a reference returned? what difference from the case 1?
}
My purpose: if class T is big, it's efficient to pass/return its reference.
The above 2 cases will do?