Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/joomla/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
String 从叮当声中混淆编译错误_String_C++11_Gcc_Clang++_Allocator - Fatal编程技术网

String 从叮当声中混淆编译错误

String 从叮当声中混淆编译错误,string,c++11,gcc,clang++,allocator,String,C++11,Gcc,Clang++,Allocator,我正在尝试为char编写一个自定义分配器,用于std::basic_string。我编写了以下代码,但它无法使用gcc.godbolt.org上的x86clang3.7进行编译-请参阅。另一方面,GCC成功地编译了它 与往常一样,有很多错误消息,其中之一是: error: 'rebind' following the 'template' keyword does not refer to a template 我迄今为止的工作: #include <algorithm> #inc

我正在尝试为
char
编写一个自定义分配器,用于
std::basic_string
。我编写了以下代码,但它无法使用gcc.godbolt.org上的x86clang3.7进行编译-请参阅。另一方面,GCC成功地编译了它

与往常一样,有很多错误消息,其中之一是:

error: 'rebind' following the 'template' keyword does not refer to a template
我迄今为止的工作:

#include <algorithm>
#include <string>
#include <iostream>
#include <type_traits>
#include <cstring>


template <typename Tp>
struct my_allocator {
};

template <>
struct my_allocator<char> {
    char arr[30];
  typedef char value_type;
  my_allocator()
  {
      std::cout<<"ctor\n";
  }
  template <class T> 
  my_allocator(const my_allocator<T>& other)
  {
      std::cout<<"copy_ctor\n";
      std::memcpy(arr,other.arr,30);
  }
  char* allocate(std::size_t )
  {
      std::cout<<"allocated\n";
      return arr;
  }
  void deallocate(char* , std::size_t )
  {
      std::cout<<"freed\n";
  }
};

typedef std::basic_string<char,std::char_traits<char>, my_allocator<char> > my_string;

int main()
{
    my_string a("hello");
    std::cout<<a;
}
#包括
#包括
#包括
#包括
#包括
模板
结构我的分配程序{
};
模板
结构我的分配程序{
char-arr[30];
typedef char value_type;
my_分配器()
{

std::coutWorks在这个clang3.7+x86_64+stdlibc++组合上很好:那里的clang配置错误,它选择了一个太旧的libstdc++。@dyp请更小心地使用您使用的名称,您可能指的是libstdc++或libc++,而不是stdlibc++。@marglisse抱歉,这仅仅是一个输入错误。我指的是libstdc++,如编译器选项所示这是我的coliru链接。