fork download
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. class array_with_offset {
  6. int offset;
  7. vector<int> data;
  8. public:
  9. array_with_offset(int N, int off)
  10. : offset(off), data(N) {
  11. }
  12. int& operator[](int index) {
  13. return data[index-offset];
  14. }
  15. };
  16.  
  17. int main() {
  18. array_with_offset ao(10, 2);
  19. for (int i = 2 ; i != 12 ; i++) {
  20. ao[i] = 2*i + 1;
  21. }
  22. for (int i = 2 ; i != 12 ; i++) {
  23. cout << ao[i] << endl;
  24. }
  25. return 0;
  26. }
Success #stdin #stdout 0s 3428KB
stdin
Standard input is empty
stdout
5
7
9
11
13
15
17
19
21
23