Boost を使用した C++ は初めてです。
クラス "world" のオブジェクトに、"octreenode" 型の "chunk" という名前の配列を持たせたいと考えています。以前は通常の 1 次元配列を使用していましたが、これはうまくいきました。現在、Boost の multi_array 機能を備えた 3D 配列の使用に移行しようとしていますが、何が間違っているのか本当にわかりません。
簡略化されたコード:
class world {
public:
typedef boost::multi_array<octreenode, 3> planetchunkarray; // a boost_multi for chunks
typedef planetchunkarray::index index;
planetchunkarray *chunk;
world(double x,double y,double z,
int widtheast, int widthnorth, int height) :
originx(x), originy(y), originz(z),
chunkseast(widtheast), chunksnorth(widthnorth), chunksup(height) {
chunk = new planetchunkarray(boost::extents[chunksnorth][chunkseast][chunksup]);
planetchunkarray::extent_gen extents;
for (int cz = 0; cz < chunksnorth; ++cz) {
for (int cx = 0; cx < chunkseast; ++cx) {
for (int cy = 0; cy < chunksup; ++cy) {
(*chunk)[cz][cx][cy] = new octreenode(1,72);
}
}
}
}
};
その後、割り当てを試みた場合
root->planet[0]->chunk[0][0][0]->material = 4;
エラーが発生します:
error: base operand of '->' has non-pointer type 'boost::detail::multi_array::sub_array<octreenode, 1u>'|
「octreenode」には関連するコンストラクターがあり、この行は次の場合と同じ構文で機能しました。
root->planet[0]->chunk[0]->material = 4;
(一次元配列)。同様に、1 次元配列で正常にコンパイルされたときに、次のような「octreenode」オブジェクトへのポインターを期待する関数にチャンクを渡そうとしました。
compactoctree (root->planet[p]->chunk[cz][cx][cy], 0, 14);
エラーを生成します
error: cannot convert 'boost::detail::multi_array::sub_array<octreenode, 1u>' to 'octreenode*' for argument '1' to 'short int compactoctree(octreenode*, int, int)'|
どんな提案にも非常に感謝しています。明らかな何かが欠けていると確信しています。