LearnCpp.com tutorials: Now with syntax highlighting!

Yup, it’s finally here. If you have a javascript enabled browser, code examples in the tutorials will now have line numbering and syntax highlighting. For example, instead of: Cents& Cents::operator= (const Cents &cSource) { // check for self-assignment by comparing the address of the // implicit object and the parameter …

14.12 — The copy constructor

Recapping the types of initialization Since we’re going to talk a lot about initialization in the next few lessons, let’s first recap the types of initialization that C++ supports: direct (parenthesis) initialization, uniform (brace) initialization or copy (equals) initialization. Here are examples of all of those, using our Fraction class: …

14.8 — Overloading the increment and decrement operators

Overloading the increment (++) and decrement (–) operators is pretty straightforward, with one small exception. There are actually two versions of the increment and decrement operators: a prefix increment and decrement (e.g. ++x; –y;) and a postfix increment and decrement (e.g. x++; y–;). Because the increment and decrement operators are …

14.5 — Overloading operators using member functions

In lesson , you learned how to overload the arithmetic operators using friend functions. You also learned you can overload operators as normal functions. Many operators can be overloaded in a different way: as a member function. Overloading operators using a member function is very similar to overloading operators using …