5

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

#include <std/bastring.h>

现在,我正在迁移到 GU g++ 4.9,我收到此错误:1.std/bastring.h未找到 2. 当我更改 #include <std/bastring.h>as#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;
                                              ^

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

4

1 回答 1

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>

我不知道是什么,ANSI X3J16/94-0013R2但它绝对与 ISO C++98 无关。如果由于某种原因您想要明确地想要并在分配器中使用,则可以在 中malloc_alloc找到 。alloc.hmallocfree

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

于 2016-06-08T11:26:20.390 回答