🚀

Copy-and-Swap Idiom (Crux)

Goal:

Safely define how objects are assigned (a = b) — especially when your class manages memory or resources.


🧠 How It Works

  1. Make a copy of the object (b).
  2. Swap its contents with a.
  3. The temporary copy (b) now holds old a data and is destroyed automatically.

That’s it!


💡 Why Use It?


🧪 Mini Example