【发布时间】:2015-08-27 05:50:12
【问题描述】:
我在我的一个类中使用来自 boost 的动态数组,并且无法为其编写适当的 getter 函数。这是我尝试过的(我检查了类 setter 中的数组大小以及 main 函数中的 getter):
#include <iostream>
#include "boost/multi_array.hpp"
using namespace std;
using namespace boost;
typedef multi_array<int, 3> array3i;
class Test {
private:
array3i test_array_;
void init(int x, int y, int z) {
array3i test_array_(extents[x][y][z]);
cout << "Size should be: " << test_array_.size() << endl;
for (int j=0; j<x; j++) {
for (int jj=0; jj<y; jj++) {
for (int jjj=0; jjj<z; jjj++) {
test_array_[j][jj][jjj] = j+jj+jjj;
}
}
}
};
public:
array3i test_array() {return test_array_;};
Test(int x, int y, int z) {
init(x, y, z);
};
};
int main(int argc, const char * argv[]) {
Test test(2,3,5);
cout << "Size from getter: " << test.test_array().size() << endl;
return 0;
}
【问题讨论】:
-
您遇到的“麻烦”是什么? 如何它不起作用?请详细说明。
标签: c++ boost multidimensional-array