class question

This is a discussion on class question within the C++ Programming forums, part of the General Programming Boards category; I need to create a clone of a class (the same class as my earlier vector topic)
the call looks ...

If you return an object, not a pointer, the program will copy your object from temp to the object you asign the result to. If you don't have a copy constructor or operator =, this will probably fail because it will copy the class bitwise. Use a pointer as stated above.

Your crash problem stems from what I was telling you in the other thread....if you have a vector of pointers, you must take special care!.....if you copy the vector to another, then the new vector recieves copies of the pointers...therefore, to pointers exist for each object on the heap....and if 1 vector calls delete on the object before going out of scope, then the second vector now refers to data that could cause a crash if its dereferenced or deleted!!!!

To get around this, your clone function must implement a deep copy to create more objects on the heap as opposed to copying references to single objects.....

Also, if you are using a clone function, you might want to keep an eye out for the copy constructor and operator=()...they must either do a deep copy too, or be made private and unusable...

Here is the code from the earlier thread.......I altered it a little to show how you can implment the Clone function

Questions:
So have I done the right thing with the function I have created?
The way I see it (which must be missing something cuz it has an error) is that:
1- It creates a new CNameValueList
2- It gets the values from the old list.
3- It pushes(creates) new CNameValue objects onto the new list
4- It returns the newly created list