#include #include using namespace std; #define DEBUG 0 // type1 = double[12]; // type2 = type1[10000]; template struct vec { T body[T2]; double & operator[](size_t elem) { #if DEBUG if (elem >= T2) { throw ...; } #endif return body[elem]; } }; #if 0 double x[12]; double y[12]; x = y; // Облом ??? vec x; vec y; x = y; // Работает! #endif using d12 = vec; #if 0 struct d12 { vector body; d12() { body.resize(12); } double & operator[](size_t elem) { return body[elem]; } }; #endif class foo { public: foo() { body.resize(10000); } d12 & operator[](size_t elem) { return body[elem]; } private: vector body; }; int func(foo &f) { f[1][5]++; return f[1][5]; } int main() { int cnt = 0; for (int i = 0; i < 10000; i++) { foo bar; cnt += func(bar); } printf("cnt=%d\n", cnt); }