#include<iostream>
#include<vector>
using std::cout;
using std::endl;
using std::vector;
const int num = 50;
class Lat;
class Lat {
public:
int x;
int y;
public:
Lat() :x(0),y(0) {}
};
template<typename Type>
class myVector :public std::vector<Type>
{
public:
Type& operator[](const int i);
};
template<typename Type>
Type &myVector<Type>::operator[](const int i)
{
return *(std::vector<Type>::begin() + (i + num));
}
int main()
{
myVector<myVector<Lat> > lat;
lat.resize(num);
for (myVector<myVector<Lat> >::iterator it = lat.begin();it < lat.end();it++)
it->resize(num);
for (int x = -num;x < 0;x++)
{
for (int y = -num;y < 0;y++)
{
lat[x][y].x = x;
lat[x][y].y = y;
}
}
for (int x = -num;x < 0;x++)
{
for (int y = -num;y < 0;y++)
cout << "(" << lat[x][y].x << "," << lat[x][y].x << ") ";
cout << endl;
}
return 0;
}
输出: