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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.