Retruning reference to object not changing the address in c++
- by ashish-sangwan
I am trying to understand function returning reference. For that i have written a simple program :-
include
using namespace std;
class test
{
int i;
friend test& func();
public:
test(int j){i=j;}
void show(){cout<
};
test& func()
{
test temp(10);
return temp; //// Address of temp=0xbfcb2874
}
int main()
{
test obj1(50); // Address of obj1=0xbfcb28a0
func()=obj1; <= Problem:The address of obj1 is not changing
obj1.show(); // // Address of obj1=0xbfcb28a0
return 0;
}
I run the program using gdb and observed that the address of obj1 still remains same but i expect it to get changed to 0xbfcb2874. I am not clear with the concept. Please help.
Thanks in advance