Chapter 6. Runtime Semantics

Imagine we have the apparently simple expression

if ( yy == xx.getValue() ) ... 

where xx and yy are defined as

X xx; 
Y yy; 

class Y is defined as

class Y { 
public: 
   Y(); 
   ~Y(); 
   operator==( const Y& ) const; 
   // ... 
}; 

and class X is defined as

class X { 
public: 
   X(); 
   ~X(); 
   operator Y() const; 
   X getValue(); 
   // ... 
}; 

Simple stuff, right? Okay, let’s look at how the expression is handled.

First, we determine the actual instance of the equality operator that is being referenced. In this case, this resolves to the overloaded Y member instance. This is the first transformation of our expression:

// resolution of intended operator 
if ( yy.operator==( xx.getValue() )) 

Y’s equality operator requires an argument of type Y. getValue() ...

Get Inside the C++ Object Model 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.