The problem is that your Buffer class does not have copy constructor. So when you initialize Class2 - it's "buf" member uses the default copy constructor, which just copies all the values from original class.
As result, both "Buffer buf" and "Buffer Cluss2::buf" point to same memory allocated by "init" of the first Buffer. And they both try to release the memory when destructed.
You should add a copy constructor to Buffer class, which will keep a copy of string in "buffer" - for example, use strdup function.
Main Topics
Browse All Topics





by: amit_gPosted on 2006-03-08 at 19:24:08ID: 16141206
How are the copy constructor and =operator written for Buffer?