Here is the code written, I wanted to that when I am returning from by reference, then it giving some garbage values, but when I am not doing so, it is giving 1 2 3 4 as answer, so how is it? It should give 1234 when returning by reference also but not so why? here is the code:-https://ide.codingblocks.com/s/454677
Concept on OOPs
Test Test::fun()
{
Test::count++;
cout << Test::count << " ";
return *this;
}
this is correct
this is a pointer so it holds the address hence you are returning reference already
what you are doing here send this code also
Test& Test::fun()
{
Test::count++;
cout<<Test::count<<" ";
return *this;
}
are you talking about this
this also works
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.
