void main(void) {
strimg temp = "first" ;
fun(temp);
cout << temp ; // should print Second
}
void fun (string& str)
{
string newString = "Second";
str = newString ;
}
This is a simple C++ program and working fine if fun() and main() are in same class but if I put fun() in different class/namespace then i get Visual C++ debug dialong box compalining of line 1132 of dbgheap.c .
I thought that assignment operator is defined for string class so when in fun() I write str = newString , str gets its own copy but then str is refrence so I guess it just points to newString so when function returns I get this error . How could I simply avoid this problem