answersLogoWhite

0

Overloading the "function call" operator, i.e. operator()(), can be achieved by defining a method with the following form:

operator()() {}

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:

operator[]( index) {}

For example:

class Subscriptable {// ...public:doubleoperator[](unsigned index) {// compute and return a double}// ...};

User Avatar

Wiki User

12y ago

What else can I help you with?

Related Questions

What do string and vector and array all inherit from that has the size method so you can take it as an argument?

string, vector and array do not have a common base class. Overload your function to accept either a string, a vector or an array.


In VB SCRIPT the first array index is always?

All languages use zero-based subscripting to index array elements because the first element is always allocated zero elements from the start address of the array. Very few languages default to a one-based subscript, however some languages, including VBScript, do allow you to change the lower-bound. Some algorithms are easier to implement with one-based subscripting, however you can also choose any lower and upper bound as appropriate.


How do you swap two adjecent no in array in c?

Option 1) Use a temporary variable: int x = array[i]; array[i] = array[i+1]; array[i+1] = x; Option 2) Use bit operators: array[i] ^= array[i+1] ^= array[i];


What is the array function in CAD?

there r 2 types of array in cad - rectangular array and polar array...........


Why the array is starting from zero?

By design; it makes the compiler's work easier. 1-based array's addressing-function: Address (array, index) = Address (array) + (index-1)*Elemsize(array) 0-based array's addressing-function: Address (array, index) = Address (array) + index*Elemsize (array)


What is an Access function for an array?

.


How is an array name interpretedwhen it is passed to a function?

An array is still an array, regardless of how you pass it into functions. It is still an array-type variable at the beginning of a function. However, the function itself may manipulate the array by "imploding" it into a string with a delimiter, using array values with only specific keys, and such.


What is the purpose of AND array?

AND array is used for developing digital circuit it is used in PLA programmable logic array and PAL programmable array of logic to implement the function. the number of and array will depend on how long you has function to be implemented.These are Digital circuits.


How do you return an array from function?

By returning a pointer to the first element of the array.


How can and array be passed to a funaction?

try this: <function-name> ( <array-name> )


How do you merge two array without using function?

Take another array big enough to hold both array copy content of these two array into new one. You merged two array and haven't used a single function.!


When an array name is passed to function in c?

It 's address is received by the function . that any changes in the value of array elements in the function will result in actual change.