【问题标题】:string_char_traits<char> in C++11 for GNU/G++ 4.9 (earlier 2.95.3)GNU/G++ 4.9(早期 2.95.3)的 C++11 中的 string_char_traits<char>
【发布时间】:2016-10-08 11:01:49
【问题描述】:

我有一些旧版 C++ 代码(用于使用 GNU g++ 2.95.3 编译)具有以下声明 std::basic_string&lt;char,string_char_traits&lt;char&gt;,malloc_alloc&gt; x; 头文件是

#include <std/bastring.h>

现在,我正在迁移到 GU g++ 4.9,但出现此错误: 1.std/bastring.h未找到 2. 当我将#include &lt;std/bastring.h&gt; 更改为#include &lt;string&gt; 时,出现以下错误:

error: 'string_char_traits' was not declared in this scope
std::basic_string<char,string_char_traits<char>,malloc_alloc> x;
error: template argument 2 is invalid
std::basic_string<char,string_char_traits<char>,malloc_alloc> x;
error: expected unqualified-id before ',' token
std::basic_string<char,string_char_traits<char>,malloc_alloc> x;
                                              ^

需要指导/帮助以使其可在 GNU g++ 4.9 下编译

【问题讨论】:

  • 你知道为什么首先使用malloc_alloc 而不仅仅是alloc吗?您可能只需使用std::string就可以逃脱惩罚。
  • @DieterLücking 致命错误:std/bastring:没有这样的文件或目录
  • @TartanLlama 我不知道为什么用 malloc_alloc 代替 alloc,你是说 std::string 会和 std::basic_string 一样吗?
  • std::string 只是 std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt;&gt; 的 typedef,所以只要默认分配器满足您的需求,就可以。

标签: c++ string c++11 g++ g++4.9


【解决方案1】:

尽管发布了 ISO/IEC 14882:1998,但 GCC 2.95.3 在很大程度上不是符合 C++98 的编译器。我们谈论的是一个 15 岁的编译器,它运行在 90 年代糟糕的谁知道什么非标准代码的尾随下。一方面,这是来自bastring.h 的sn-p:

// Written by Jason Merrill based upon the specification by Takanori Adachi
// in ANSI X3J16/94-0013R2.

...

// NOTE : This does NOT conform to the draft standard and is likely to change
#include <alloc.h>

我不知道ANSI X3J16/94-0013R2 是什么,但它绝对与ISO C++98 无关。 malloc_alloc 位于 alloc.h 中,如果出于某种原因您想明确希望在分配器中使用 mallocfree

无论如何,您的代码库无疑必须从头开始重写。 std::basic_string&lt;char,string_char_traits&lt;char&gt;,malloc_alloc&gt; x; 可以替换为 std::string。但我对其中包含的其他预标准代码的恐惧感到不寒而栗。

【讨论】:

  • ANSI X3J16/94-0013R2 是 1994 年的 C++ 委员会论文。(ANSI X3J16 是美国 C++ 委员会。)不幸的是,它似乎无法在线获得。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-03-22
  • 1970-01-01
  • 2015-01-19
  • 1970-01-01
  • 2015-10-02
相关资源
最近更新 更多