5
this code가 컴파일되지 않는 이유는 무엇입니까?사용자 지정 할당 자 및 기본 멤버
#include <cstdlib>
#include <list>
template < typename Type >
class Allocator {
public:
using value_type = Type;
public:
template < typename Other >
struct rebind { using other = Allocator<Other>; };
public:
Type * allocate(std::size_t n) { return std::malloc(n); }
void deallocate(Type * p, std::size_t) throw () { std::free(p); }
};
int main(void) {
std::list< void *, Allocator< void * > > list;
return 0;
}
포인터, 참조, pointer_const & reference_const 유형을 필요로하는 것 같다. 그러나 cppreference에 따르면이 구성원은 모두 선택 사항입니다. STL이 allocator_trait를 사용하지 않는 것처럼 보입니다. (-std = C++ 11로 컴파일해야합니다.)
아이디어가 있으십니까? 그 소리에
[편집] 오류는 다음과 같습니다
[email protected]/tmp > clang++ -std=c++11 test.cc
In file included from test.cc:2:
In file included from /usr/lib/gcc/i686-pc-linux-gnu/4.7.1/../../../../include/c++/4.7.1/list:63:
/usr/lib/gcc/i686-pc-linux-gnu/4.7.1/../../../../include/c++/4.7.1/bits/stl_list.h:449:40: error: no type named 'pointer' in 'Allocator<void *>'
typedef typename _Tp_alloc_type::pointer pointer;
~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
test.cc:17:46: note: in instantiation of template class 'std::list<void *, Allocator<void *> >' requested here
std::list< void *, Allocator< void * > > list;
^
In file included from test.cc:2:
In file included from /usr/lib/gcc/i686-pc-linux-gnu/4.7.1/../../../../include/c++/4.7.1/list:63:
/usr/lib/gcc/i686-pc-linux-gnu/4.7.1/../../../../include/c++/4.7.1/bits/stl_list.h:450:40: error: no type named 'const_pointer' in 'Allocator<void *>'
typedef typename _Tp_alloc_type::const_pointer const_pointer;
~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~
/usr/lib/gcc/i686-pc-linux-gnu/4.7.1/../../../../include/c++/4.7.1/bits/stl_list.h:451:40: error: no type named 'reference' in 'Allocator<void *>'
typedef typename _Tp_alloc_type::reference reference;
~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~
/usr/lib/gcc/i686-pc-linux-gnu/4.7.1/../../../../include/c++/4.7.1/bits/stl_list.h:452:40: error: no type named 'const_reference' in 'Allocator<void *>'
typedef typename _Tp_alloc_type::const_reference const_reference;
~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~
4 errors generated.
무엇이 오류입니까? – Nick
@ 닉 나는 clang 출력으로 내 질문을 업데이트했다. (gcc도 실패하고있다.) –
기본적으로 모든 컴파일러에 대한 C++ 11 지원은 여전히 시험/불완전하다. 그러므로 단순히 구현 버그 일 수 있습니다. (현재 표준의 관련 부분을 찾을 수 없으므로 그 구성원이 실제로 선택 사항인지 여부는 추측입니다) – Grizzly