Introduction to OOP: Chapter 4: Messages, Instances, and Initialization: [next] [previous] [audio] [real] [text]

Operators as Messages

In some languages (Smalltalk, C++) operators can also be defined as methods.

When used in this fashion the receiver is the left argument, while the right argument is the single parameter used by the method.

a + b

class rational {
	rational operator + (rational & right) { ... }
Intro OOP, Chapter 4, Slide 9