【问题标题】:Compiler error for std::string in c++ builder XE3 projectc++ builder XE3项目中std :: string的编译器错误
【发布时间】:2016-01-16 11:25:18
【问题描述】:

我正在使用 c++ builder XE3 开发服务应用程序。 如果我添加这一行,我会收到 std::string 的编译器错误:

string a = string("abcd") + "xyz";

错误输出如下:

[bcc32 Error] string(141): E2285 Could not find a match for 'move<_Ty>(string)'
  Full parser context
string(140): decision to instantiate: string std::string + <char,char_traits<char>,allocator<char> >(string &&,const char *)
--- Resetting parser context for instantiation...
svcmain.cpp(21): #include C:\Program Files\Embarcadero\RAD Studio\10.0\include\boost_1_39\boost\tr1\tr1\string
string(20): #include c:\program files\embarcadero\rad studio\10.0\include\../include/dinkumware/string
string(7): namespace std
string(140): parsing: string std::string + <char,char_traits<char>,allocator<char> >(string &&,const char *)

我尝试在#include &lt;string&gt; 上方添加#include &lt;utility&gt;,但仍然出现同样的错误。 相反,如果我将这一行分成两部分,如下所示,它编译时不会出错。

string a = string("abcd");
a += "xyz";

string b = string("abcd");
string a = b + "xyz";

使用这种解决方法是不切实际的,因为我必须使用现有的代码,而该代码不会出现大量错误。相同的代码在其他 XE3 项目中没有错误。 任何想法如何解决此错误?

【问题讨论】:

  • 您使用的是using namespace std 语句吗?不。只需在类型声明中完全限定 std 命名空间:std::string a = std::string("abcd") + "xyz"; 错误消息表明您将 Boost 的 string 标头与 Dinkumware 的 string 标头混合,因此您可能会遇到命名空间冲突。
  • 我已经尝试过了,但仍然遇到同样的错误。我检查了所有包含的头文件都没有using namespace 语句。根本没有使用 Boost。
  • 根本不使用Boost” - 不是根据您的错误消息。 svcmain.cpp 包括$(BDS)\include\boost_1_39\boost\tr1\tr1\string,而$(BDS)include\dinkumware\string 又包括$(BDS)include\dinkumware\string

标签: c++ windows c++builder-xe3


【解决方案1】:

我在另一个项目中找到了修复程序。将“向后兼容性”选项设置为 false 可修复错误。 您可以在 - 项目选项 -> C++ 编译器 -> 兼容性 -> 常规中找到复选框。 这最初设置为 true。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-03-20
    • 1970-01-01
    • 2016-01-07
    • 2016-12-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多