T
Tony Johansson
Hello Experts!
I'm reading in a book about C++ and the book says common errors is
"A function should not return a constant references to its parameter passed
by constant references"
Why?
Here I have written a method that has exactly this which is the parameter is
passed by constant references and I return constant references what is it
that can cause common error by writng in this way.
main()
{
int tal = 9;
Test t;
t.foo(tal);
}
class Test
{
const int& foo(const int& i)
{
return i;
}
};
Many thanks
//Tony
I'm reading in a book about C++ and the book says common errors is
"A function should not return a constant references to its parameter passed
by constant references"
Why?
Here I have written a method that has exactly this which is the parameter is
passed by constant references and I return constant references what is it
that can cause common error by writng in this way.
main()
{
int tal = 9;
Test t;
t.foo(tal);
}
class Test
{
const int& foo(const int& i)
{
return i;
}
};
Many thanks
//Tony