Jump to content

C++ Language/Objects/OperatorOverloading

From Wikibooks, open books for an open world

Programming custom implementations for operators is the mechanism for allowing a custom C++ class to be used as a "value type" (which then can behave similar to built-in primitive types like int). For example, client code expects to be able to do int iX = iY + iZ + 9;; if you want your custom class to also behave that way, then define its const CRType CRType::operator+(const CRType& aroRhs) {body}.

Additional information about operator overloading (includes interactive examples)