의 모음 인 Matrix
클래스가 있습니다.-std = C++ 0x를 사용할 때 사용자 정의 할당자를 사용하여 컴파일 문제가 발생했습니다.
행 :
template <typename Index>
class Row {
public:
Row()
{
_index_vector = std::vector<Index, aligned_allocator<Index> >();
}
Row& operator=(const Row& source)
{
//some copy logic here
return *this;
}
private:
std::vector<Index, aligned_allocator<Index> > _index_vector;
};
매트릭스 :가
template <typename Index>
class Matrix {
public:
typedef std::vector<Row<Index> > Rep;
Matrix() : _m (0), _n (0)
{}
Matrix (size_t n, size_t m) :
_m (m),
_n (n)
{
_A = Rep (n);
}
private:
Rep _A;
size_t _m;
size_t _n;
};
Row
데이터 타입은 할당을 사용하여, 주요 기능은 다음과
template <class T>
class aligned_allocator
{
public:
//Other methods; members...
pointer allocate (size_type size, const_pointer *hint = 0) {
pointer p;
posix_memalign((void**)&p, 16, size * sizeof (T));
return p;
};
void construct (pointer p, const T& value) {
*p=value;
};
void destroy (pointer p) {
p->~T();
};
void deallocate (pointer p, size_type num) {
free(p);
};
};
내가
-std=c++0x
없이이를 컴파일 할 때이 오류없이 컴파일
#include "types.h"
int main(int argc, char **argv)
{
Matrix<int> AA (100, 100);
}
: 16,
나는 코드를 테스트하기 위해 간단한 프로그램을 사용합니다.
error: invalid operands to binary expression ('_Tp_alloc_type'
(aka 'aligned_allocator<int>') and '_Tp_alloc_type')
if (__x._M_get_Tp_allocator() == this->_M_get_Tp_allocator())
./types.h:26:17: note: in instantiation of member function 'std::vector<int, aligned_allocator<int> >::operator=' requested here
_index_vector = std::vector<Index, aligned_allocator<Index> >();
은 무엇 이것에 대한 이유가 될 수있다 : -std=c++0x
을 사용하는 경우 그러나, 나는 다음과 같은 오류가? 가능한 해결 방법/해결 방법. gcc version 4.7.2
및 clang version 3.1
을 사용하고 있습니다.
(. 긴 코드에 대한 유감)은 운영자 ==를 가질> aligned_allocator <을 원한다처럼