C++ Tutorial/Operator Overloading/overload address of operator — различия между версиями

Материал из C\C++ эксперт
Перейти к: навигация, поиск
м (1 версия: Импорт контента...)
 
(нет различий)

Версия 17:21, 25 мая 2010

Overload & operator

<source lang="cpp">#include <iostream> using namespace std; class Point {

 int a[3];

public:

 Point(int i, int j, int k) {
   a[0] = i;
   a[1] = j;
   a[2] = k;
 }
 int &operator[](int i) { return a[i]; }

}; int main() {

 Point ob(1, 2, 3);
 cout << ob[1]; // displays 2
 cout << " ";
 ob[1] = 25; // [] on left of =
 cout << ob[1]; // now displays 25
 return 0;

}</source>

10 10"