Overloading Class Methods and Operators
List of: Discussion Topic
Subjects: C++ Interface
Contents: Fundamental Concepts

ACIS overloads operators, such as the minus operator (-). This permits the proper handling of elements, depending on the particular class. For example, when one position is subtracted from another, the result is the vector that goes between the two positions, as is shown by the instance of the SPAvector class in Example 2-4.

C++ Example

SPAposition p1 (3, 4, 5);
SPAposition p2 (6, 7, 8);
SPAvector v1 = p2 - p1;

Example 2-4. Overloaded Operators

ACIS makes use of the fact that C++ is a strongly typed to enforce rules of combination. For example, the concept of adding two positions does not make sense. However, it does make sense to create a new position that is the sum of a position and a vector, as is shown in Example 2-5, which creates a new instance of the SPAposition class by adding a previous SPAposition instance to a SPAvector instance.

C++ Example

SPAposition p1 (3, 4, 5);
SPAposition p2 (6, 7, 8);
SPAposition p3 = p1 + p2; // Error: this does not compile
SPAvector v1 (10, 20 , 30);
SPAposition p4 = p1 + v1; // creates a new position offset from






// position p1 by vector v1.

Example 2-5. Using C++ Strong Types
PDF/FCG/02CPLUS.PDF
HTM/DATA/ACIS/FCG/02CPLUS/0004.HTM