boost::multi_array
기반으로 2 차원 배열 클래스를 만들려고합니다. 나는 아래에 주어진 코드에서 두 가지 이슈에 직면 해있다. (1) 멤버 함수 col()
에 대한 코드는 컴파일하지 않습니다. ::type’ has not been declared
. 내가 어디로 잘못 가고 있니? (2) 클래스 외부에서 멤버 함수 data()
을 정의 할 수 있습니까? 내 시도 typedefs 사용할 수 없으므로 컴파일 오류를 제공합니다. 하지만 typedef는 템플릿 클래스 내에서만 사용할 수있는 T
유형을 필요로하므로 클래스 외부의 typedef를 정의 할 수 없습니다. 감사.2 차원 배열에서 boost :: multi_array - 컴파일 할 수 없습니다.
#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]);
}
나는 컴파일러 오류 메시지와 K-ballo의 입력을 통해 알아 냈습니다. 그러나 왜'template' 요구 사항입니까? – suresh
@suresh : 내 편집보기 –
@suresh : 자세한 내용은 다음 FAQ를 참조하십시오. [[-> template','.template' 및':: template' 구문은 무엇입니까?] (http : // www. comeaucomputing.com/techtalk/templates/#templateprefix) – ildjarn