に基づいて 2 次元配列クラスを作成しようとしていますboost::multi_array
。以下のコードで 2 つの問題に直面しています。(1) メンバー関数のコードcol()
はコンパイルされません::type’ has not been declared
。どこが間違っていますか?data()
(2)クラス外でメンバー関数を定義することは可能ですか? typedef を使用できないため、コンパイル エラーが発生します。T
しかし、typedefはテンプレート クラス内でのみ使用できる型を必要とするため、クラス外で typedef を定義することはできません。ありがとう。
#include <boost/multi_array.hpp>
#include <algorithm>
template <class T>
class Array2d{
public:
typedef typename boost::multi_array<T,2> array_type;
typedef typename array_type::element element;
typedef boost::multi_array_types::index_range range;
//is it possible to define this function outside the class?
Array2d(uint rows, uint cols);
element * data(){return array.data();}
//this function does not compile
template<class Itr>
void col(int x, Itr itr){
//copies column x to the given container - the line below DOES NOT COMPILE
array_type::array_view<1>::type myview = array[boost::indices[range()][x]];
std::copy(myview.begin(),myview.end(),itr);
}
private:
array_type array;
uint rows;
uint cols;
};
template <class T>
Array2d<T>::Array2d(uint _rows, uint _cols):rows(_rows),cols(_cols){
array.resize(boost::extents[rows][cols]);
}