-1

I'm having a lot of trouble with operator overloading. I'm just not sure what it's used for, and when it should be used to generate a desired result. This closely ties with my confusion that, when creating a copy constructor (which, as I understand, is called whenever a function passes-by-value an object of the class type), it's generally understood that the = assignment operator should be overloaded and a destructor should be explicitly defined.

Any help would be greatly appreciated.

Aleksander Blomskøld
  • 18,374
  • 9
  • 76
  • 82
Bob John
  • 3,688
  • 14
  • 43
  • 57

1 Answers1

0

That's two questions. The one about the Rule of Three has been answered in another topic (spoiler: If you're implementing one of them, you're probably managing a resource and if you do, you should implement the other two to manage that resource right).

For a short answer on the use of operator overloading, compare the syntax for a matrix library that requires this:

M.multiply( a).plus( N).plus( A.multiply( B));

or even:

plus( plus( multiply( a, M), N), multiply( A,B));

with:

a * M + N + A * B;
Community
  • 1
  • 1
dhavenith
  • 2,028
  • 13
  • 14