operator[][]のやり方。

#include <iostream>
#include <vector>
using namespace std;

template<class T> class array {
public: int m; vector< vector<T> > *vec;
T& operator[](int n) { return (*vec)[m][n]; } };


template<class T> class arrays {
vector< vector<T> > vec;
array<T> prx;
public:
arrays(int x,int y) {
vec = vector< vector<T> >( x, vector<T>(y) );
prx.vec = &vec; }
array<T>& operator[](int m) { prx.m = m; return prx; }
};


int main () {
arrays<int> array(3,5);
int m,n;
for(m=0;m<3;m++) for(n=0;n<5;n++) array[m][n] = (m+1)*(n+1);
for(m=0;m<3;m++) {
for(n=0;n<5;n++) printf("%3d", array[m][n]);
printf("\n"); }}