float& function (float x) {
float y = x;
return y;
}
function return's reference.
reference to what???
how function can have as return type& , I mean when is it used ref as return?
or if u use sobjects or any example how to use this kind of function properly.
WHAT'S THIS:
1 2 3 4 5 6 7
template <class elem>
elem& manjiUNizu (elem* niz, int br) {
elem* ptrNajmanji = niz;
for (short i = 1; i < br; i++)
if (niz [i] < *ptrNajmanji) ptrNajmanji = &niz [i];
return *ptrNajmanji;
}
what will this function return exactly please explain.
thanks!
The second example is returning a reference to the value at ptrNajmanji - which is a valid memory location on the heap. That reference will be valid until delete is called on that pointer.