Conversions Between Nonrelated Classes
As stated earlier, C++ aspires to support the concept of strong typing. I would like to make sure that you find this principle of modern programming intuitively natural and appealing: If the code context expects an object of a particular type, it is a syntax error to use an object of a different type instead.
What are possible contexts where this rule is important? They include:
expressions and assignments
function arguments (including pointers and references)
objects used as targets of messages
I will call two different classes nonrelated if neither of them serves as a direct or indirect base class for another class. Notice that the classes that are not related to each other through inheritance might be ...
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.