[cs13001] Overloading operator.

Mikhail Nesterenko mikhail at cs.kent.edu
Sun Nov 18 10:00:37 EST 2012


> 
> While reading the slides and the book, I realized that the slides write it like this:  bool equal(const Date& date 1, const Date& date2);
> 
> But in the book it's written like this: friend Money operator +(const Money& amount1, const Money& amount2); 
> 

Bot in slides and in the book equal is declared as friend. 


> While I realize that I don't necessarily have to write friend, and I
> can choose whether or not to write == or equal, what I'm wondering
> is, why does the book always use operator in the code?

Well, there are two schools of thought on operator overloading. C++
uses it to preserve the intuitive meaning of standard operators when
applied to non-standard types (classes). More modern languages do not
allow operator overloading because the programs are considered harder
to underhand.

Thanks,
--
Mikhail


More information about the cs13001 mailing list