也许你可以使用这个:
#include <iostream>
#include <string>
#include <boost/multi_array.hpp>
#include <boost/array.hpp>
#include <boost/cstdlib.hpp>
namespace{
constexpr size_t dim1_size = 3;
constexpr size_t dim2_size = 3;
constexpr size_t dim3_size = 3;
constexpr size_t dim4_size = 3;
constexpr size_t dim5_size = 3;
void print(std::ostream& os, const boost::multi_array<double, 5>& a){
os<<"implementation of print: "<<a[0][0][0][0][0]<<std::endl;
}
boost::multi_array<double, 5> createArray(){
return boost::multi_array<double, 5>(boost::extents[dim1_size][dim2_size][dim3_size][dim4_size][dim5_size]);
}
}
class myClass {
public:
boost::multi_array<double, 5> myArray = createArray();
void printArray(){
print(std::cout, myArray);
}
};
int main()
{
myClass a;
a.myArray[0][0][0][0][0] = 42;
a.printArray();
}
要在函数中传递 a boost::multi_array
,您可以使用 in 之类的引用print
。要创建一个boost::multi_array
,您必须将其作为副本返回。编译器可能会将其优化为移动。