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 के अनुसार ये सदस्य सभी विकल्प हैं। ऐसा लगता है कि एसटीएल 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
@ निक मैंने अपने प्रश्न को क्लैंग आउटपुट के साथ अपडेट किया है (जीसीसी भी असफल रहा है) –
ध्यान दें कि मूल रूप से सभी कंपाइलरों के लिए C++ 11 समर्थन अभी भी प्रयोगात्मक/अपूर्ण है। इसलिए यह केवल कार्यान्वयन बग हो सकता है (अभी मानक के प्रासंगिक हिस्सों को नहीं देख सकता है, इसलिए यह अनुमान है कि यदि वे सदस्य वास्तव में वैकल्पिक हैं) – Grizzly