得到歧义符号的错误,需要帮助删除它 [英] getting error for ambiguous symbol and need help to remove it

查看:237
本文介绍了得到歧义符号的错误,需要帮助删除它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到这个错误,我无法在visual studio 2010中删除。我使用一个第三方库,它使用自己的定义字符串另外visual studio的xstring文件是在那里安装的文件夹中。现在当我试图编译代码,我得到以下错误

i am getting this error which i unable to remove in visual studio 2010. i am using one third party library which uses its own definition for "string" Also visual studio's xstring file is there in the folder where it gets installed. now when i am trying to compile code i am getting following error

1> ... \xyz.cpp(24):error C2872:'string':ambiguous符号
1>可以是第三方库路径\string.h(31)
1>或'c:\program文件(x86)\microsoft visual studio 10.0 \vc\ include \xstring(2063):std :: string'

1>...\xyz.cpp(24): error C2872: 'string' : ambiguous symbol 1> could be 'third party library path\string.h(31) 1> or 'c:\program files (x86)\microsoft visual studio 10.0\vc\include\xstring(2063) : std::string'

编译器无法理解应该使用哪个字符串定义。我想在代码中使用第三方字符串定义。

compiler is not able to understand which string definition it should use. How can i remove this error in visual studi 2010. I want the code to use third party string definition.

我试图在包含目录中设置第三方路径,但仍然是我看到这个错误。
请帮帮我。提前感谢

i tried to set third party path in include directory but still i am seeing this error. Please help me. Thanks in advance

推荐答案

这是命名空间冲突的示例。您的代码中可能有以下代码:

This is an example of a namespace clash. You probably have in your code:

#include <3rdPartyString.h> // declaration of 3rd party string type
#include <string> // declaration of std::string
using namespace 3rdPartyNamespace;
using namespace std;
...
string myStr; // which string type?

编译器现在不知道要使用哪个字符串 - 一个来自第三方库或STL 。您可以通过将命名空间名称添加到类型来解决此歧义:

Compiler now doesn't know which string you want to use - one from 3rd party library or STL one. You can resolve this ambiguity by prepending namespace name to the type:

3rdPartyNamespace::string myStr; // if you want to use string from 3rd party library

std::string myStr; // if you want to use STL string

不要使用namespace namespace_name放置 在标题,但尽量避免它在源文件以及。最好的做法是预先添加类型名称,因为这不会污染您当前的命名空间,因此避免命名空间冲突。

Never place using namespace namespace_name; in headers but try to avoid it in source files as well. The best practice is to prepend type name as this does doesn't pollute your current namespace with the other one thus avoiding namespace clashes.

这篇关于得到歧义符号的错误,需要帮助删除它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆