Limitations on Operator Overloading

As you saw in the previous section, the overloaded operators give you a powerful tool to make C++ code more beautiful by treating objects of programmer-defined types similarly to variables of built-in numeric types. There are, however, some limitations that C++ places on the use of overloaded operators. Some of these operations will not limit you much, but some are quite essential. In this section, I will discuss these limitations.

What Operators Cannot Be Overloaded

There are some limitations on operator overloading that are not very important for the practicing programmer, at least not at this stage. You cannot overload operator :: (scope), operator .* (member object selector), operator . (class object ...

Get Core C++ A Software Engineering Approach now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.