Overloading the "function call" operator, i.e. operator()(), can be achieved by defining a method with the following form:
For example, here's how it would look in the simplest case (no argument or return value):
class Callable {// ...public:voidoperator()() {// do something interesting}// ...};
Overloading the array subscript operator, i.e. operator[](), is just as easy. This operator always takes a single argument (the subscript). Here's a template for a method which overloads this operator:
For example:
class Subscriptable {// ...public:doubleoperator[](unsigned index) {// compute and return a double}// ...};
Copyright © 2026 eLLeNow.com All Rights Reserved.