Explicit Conversion Operators

This lesson explains how conversion operators can be overloaded explicitly in C++.

We'll cover the following

Asymmetry in C++98 #

In C++98, the explicit keyword was only supported for conversion constructors. Conversion operators converted user-defined objects implicitly.

All this changed in C++11. Now, we can overload conversion operators to explicitly prevent and permit conversions.

Let’s suppose that a class called MyClass can perform conversions from class A to MyClass and from MyClass to class B.

Get hands-on with 1400+ tech skills courses.