Overload []. : Index « Overload « C++
- C++
- Overload
- Index
Overload [].
![Overload [].](https://web.archive.org/web/20150825033512im_/http://www.java2s.com/Code/CppImages/Overload.PNG)
#include <iostream>
using namespace std;
const int SIZE = 3;
class MyClass {
int a[SIZE];
public:
MyClass() {
register int i;
for(i = 0; i <SIZE; i++)
a[i] = i;
}
int operator[](int i) {
return a[i];
}
};
int main()
{
MyClass myObject;
cout << myObject[2];
return 0;
}
Related examples in the same category