Jeffrey Walton noloader@gmail.com
Mon Aug 15 23:31:00 GMT 2011

Hi All,

I'm testing a custom allocator. The allocator works well with vector,
but fails to link with basic_string (see below).

I looked through Stroustrup and could not find info on _Alloc_hider.
Searching online doesn't reveal much either (perhaps I have not waded
through enough irrelevant fodder). I did find [1], buts its just
DoOxygen with no real content (its written in STL terseness with no

I believe I need another constructor, but I'm not sure what it takes
or how to write it:

  inline explicit zallocator() { }
  inline ~zallocator() { }
  inline explicit zallocator(zallocator const&) { }

  template<typename U>
  inline explicit zallocator(zallocator<U> const&) { }

How does one one provided an allocator for use by a basic_string?


[1] http://gcc.gnu.org/onlinedocs/libstdc++/libstdc++-html-USERS-4.3/a00073.html


typedef basic_string< char, char_traits<char>, zallocator<char> > String;
String str = "Goodbye, world";

$ g++ -g3 -ggdb -O0 AllocTest.cpp -o AllocTest.exe
In file included from /usr/include/c++/4.5/string:53:0,
                 from /usr/include/c++/4.5/bits/locale_classes.h:42,
                 from /usr/include/c++/4.5/bits/ios_base.h:43,
                 from /usr/include/c++/4.5/ios:43,
                 from /usr/include/c++/4.5/ostream:40,
                 from /usr/include/c++/4.5/iostream:40,
                 from SecAllocTest.cpp:3:
/usr/include/c++/4.5/bits/basic_string.h: In member function
‘allocator_type std::basic_string<_CharT, _Traits,
_Alloc>::get_allocator() const [with _CharT = char, _Traits =
std::char_traits<char>, _Alloc = zallocator<char>, allocator_type =
/usr/include/c++/4.5/bits/basic_string.h:525:9:   instantiated from
‘std::basic_string<_CharT, _Traits, _Alloc>::~basic_string() [with
_CharT = char, _Traits = std::char_traits<char>, _Alloc =
SecAllocTest.cpp:103:22:   instantiated from here
/usr/include/c++/4.5/bits/basic_string.h:1741:16: error: no matching
function for call to
std::char_traits<char>, zallocator<char> >::_Alloc_hider&)’

More information about the Gcc-help mailing list