Question about an example of The Rule of Two.

Started by
2 comments, last by MarkS_ 10 years, 8 months ago
L. Spiro posted this in another thread: http://www.artima.com/cppsource/bigtwo3.html

I find the concept fascinating, but I have a some questions about two of the RAII class member functions.

1.) What does the reset function do? What I see happening is it deleting the member pointer and then assigning the pointer passed into the function to the deleted pointer. How does that work? Is that legal C++?

2.) What purpose is there for the swap function? Apart from sorting pointers, is there any other reason for its existence?
Advertisement

I figured out reset.

Still unsure about swap...

For implementing the copy and swap idiom for assignment? See the top reply to this question:

http://stackoverflow.com/questions/3279543/what-is-the-copy-and-swap-idiom

"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley

Thank you! That explains a lot!

This topic is closed to new replies.

Advertisement