Navigation



9.10 — Overloading typecasts

In the lesson on type conversion and casting, you learned that C++ allows you to convert one data type to another. The following example shows an int being converted into a double:

int nValue = 5; double dValue = nValue; // int implicitly cast to a double

C++ already knows how to convert between . . . → Read More: 9.10 — Overloading typecasts

9.9 — Overloading the parenthesis operator

All of the overloaded operators you have seen so far let you define the type of the operator’s parameters, but the number of parameters is fixed based on the type of the operator. For example, the == operator always takes two parameters, whereas the logical NOT operator always takes one. The parenthesis operator (()) . . . → Read More: 9.9 — Overloading the parenthesis operator

7.12 — Handling errors (assert, cerr, exit, and exceptions)

When writing programs, it is almost inevitable that you will make mistakes. In this section, we will talk about the different kinds of errors that are made, and how they are commonly handled.

Errors fall into two categories: syntax and semantic errors.

Syntax errors

A syntax error occurs when you write a statement that . . . → Read More: 7.12 — Handling errors (assert, cerr, exit, and exceptions)

9.8 — Overloading the subscript operator

When working with arrays, we typically use the subscript operator ([]) to index specific elements of an array:

anArray[0] = 7; // put the value 7 in the first element of the array

However, consider the following IntList class, which has a member variable that is an array:

class IntList { private: int m_anList[10]; . . . → Read More: 9.8 — Overloading the subscript operator

9.7 — Overloading the increment and decrement operators

Overloading the increment (++) and decrement (–) operators are pretty straightforward, with one small exception. There are actually two versions of the increment and decrement operators: a prefix increment and decrement (eg. ++nX; –nY;) and a postfix increment and decrement (eg. nX++; nY–;).

Because the increment and decrement operators modify their operands, they’re best . . . → Read More: 9.7 — Overloading the increment and decrement operators