Value get changed even though I'm not using reference
- by atch
In code:
struct Rep
{
const char* my_data_;
Rep* my_left_;
Rep* my_right_;
Rep(const char*);
};
typedef Rep& list;
ostream& operator<<(ostream& out, const list& a_list)
{
int count = 0;
list tmp = a_list;//----->HERE I'M CREATING A LOCAL COPY
for (;tmp.my_right_;tmp = *tmp.my_right_)
{
out << "Object no: " << ++count << " has name: " << tmp.my_data_;
//tmp = *tmp.my_right_;
}
return out;//------>HERE a_list is changed
}
I've thought that if I'll create local copy to a_list object I'll be operating on completely separate object. Why isn't so?
Thanks.