int main() { Cents cMark(5); // calls Cents constructor Cents cNancy = cMark; // calls Cents copy constructor! std::cout << cNancy.getCents() << "\n"; return 0; }
int main() { Cents cents1(6); Cents cents2(2); Cents centsSum = cents1 - cents2; std::cout << "I have " << centsSum.getCents() << " cents." << std::endl; return 0; }
const Cents operator -(const Cents &c) { return (-c.cents()); }
bool operator ==(const Cents &c1, const Cents &c2) { return (c1.cents() == c2.cents()); }
// This function is NOT a member function! const Cents operator -(const Cents &c1, const Cents &c2) { // Use the Cents constructor and operator-(int, int) return Cents(c1.cents() - c2.cents()); }
void PrintCents(Cents cCents) { std::cout << cCents.GetCents() << std::endl; }