ハイパーキューブクラス、つまり多次元ベクトルを実装しようとしています。一般化に問題があります。三次元超立方体用に作ることはできますが、前述のように、問題はそれを一般化することです。誰か助けてもらえますか?hypercube<4> w(5)
合計で5*5 * 5*5要素である各ベクトルの4つの次元と5つの要素を取得するように書くことができるはずです。
これが私が3次元バージョンのために持っているコードです:
#include <vector>
using std::vector;
using namespace std;
template <int b>
class Hypercube {
public:
Hypercube(int a) : intvec(a){
for (int i = 0; i<a;i++) {
intvec[i].resize(a);
for (int j = 0;j<a;j++) {
intvec[i][j].resize(a);
}
}
}
vector<vector<int> >& operator[](int i) {
return intvec[i];
}
vector<vector<vector<int> > > intvec;
};