I am really confused how compiler allocates STL objects. Consider the following code:

```
#include <string>

using namespace std ;

class s { 
    public:
    string k ; 

    s(string k) : k(k) {}
} ;

void x ( s obj ) {
    string k = (obj.k) ;
    k += "haha" ;

}

int main () {
    std::string mystr ("laughter is..") ;
    s mys(mystr) ;
    x(mys) ;

    printf ("%s", mystr.c_str() ) ;
}

```

The output of this program is `laughter is..` and I expect the output to be:
`laughter is haha`

Why doesn't mystr string get `haha` . I need to store it in a class as a part of my code. 

If I had passes mystr by value to function x, the string mystr would have got `haha` into it. 

a) How and when do STL objects get allocated? I supposed mystr is on a stack and must be accessible to all functions called from main() .

b) What if I need to store STL objects in a old fashioned Linked list which needs "void\*". Cant I just do:

```
std::string mystr ("mystring.." );

MyList.Add((void*)&mystr) ;

fun(MyList) ;

```

Can the function fun, now use and modify mystr by accessing MyList ?

c) As an alternative to (b) , can I use pass by reference. The issue is can I declare a class to keep a reference of mystr? I mean the constructor of MyList can be like this:

```
class MyList { 
    string& mStr ;
    ...
};

MyList::MyList ( string& mystr ) {
      mStr = mystr ;

}

```

Is that constructor valid ? Is that class valid?