用于GNU/G ++ 4.9的C++ 11中的string_char_traits <char>(早于2.95.3)

Dr.*_*ana 5 c++ string g++ c++11 g++4.9

我有一些遗留的C++代码(用于使用GNU g ++ 2.95.3进行编译)具有以下声明 std::basic_string<char,string_char_traits<char>,malloc_alloc> x; 头文件是

#include <std/bastring.h>
Run Code Online (Sandbox Code Playgroud)

现在,我迁移到GU G ++ 4.9在那里我得到这个错误:1,std/bastring.h未发现2.当我改变的#include <std/bastring.h>因为#include <string>,我发现了以下错误:

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;
                                              ^
Run Code Online (Sandbox Code Playgroud)

在GNU g ++ 4.9下需要指导/帮助才能使这个可编辑

uh *_*per 1

尽管发布了 ISO/IEC 14882:1998,但 GCC 2.95.3 并不是一个符合 C++98 的编译器。我们谈论的是一个已有 15 年历史的编译器,运行在 90 年代可怕的、谁知道是什么非标准代码的支持下。一方面,这里有一个片段bastring.h

// 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>
Run Code Online (Sandbox Code Playgroud)

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

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