不明确的符号
Ambiguous symbol
我在自定义命名空间中声明了一个类Integer:
namespace MyNameSpace
{
class Integer {};
}
我用这样的方法:
void someMethod()
{
using namespace MyNameSpace;
SomeClass x(Integer("some text", 4));
}
这提供
10> error C2872: 'Integer' : ambiguous symbol
10> could be 'g:libboostboost_1_47_0boost/concept_check.hpp(66) : boost::Integer'
10> or '[my file] : MyNameSpace::Integer'
我在我的代码库中搜索了全文搜索中的"namespace-boost"answers"usingboost",但没有找到像"usingnamespace-brust;"这样的行。的测试支持了这一点
void someMethod()
{
shared_ptr<int> x;
using namespace MyNameSpace;
//SomeClass x(Integer("some text", 4));
}
给出
error C2065: 'shared_ptr' : undeclared identifier
而
void someMethod()
{
boost::shared_ptr<int> x;
using namespace MyNameSpace;
//SomeClass x(Integer("some text", 4));
}
编译。
"模糊符号"错误发生的原因还有其他原因吗??
编译器只是防止您混淆这些类。即使您不使用命名空间"boost"。
命名空间本质上是其中内容的"姓氏"或"姓氏"。在您的例子中,Integer()的全名是MyNameSpace::Integer(。您的特定错误是使用名称空间的第一条规则的一个极好的例子。不要使用"USING"语句!如果你完全忽略了它们,是的,你必须键入一些额外的东西来安抚编译器。但你永远不会有碰撞,也不会问"boost在某个地方有整数吗"之类的问题。
其次,someMethod()在任何类和任何命名空间之外。它确实应该看起来更像MyNameSpace::Integer::someMethod(),或者更合理地位于内部
namespace MyNameSpace
{
Integer::someMethod(
}
一旦你这样做,编译器将帮助你找到东西在哪里或不在哪里。
祝你好运!
相关文章:
- Visual C++(VS2017)中用户定义的转换不明确
- 重载类方法的不明确调用
- C4018:类内有符号、无符号不匹配
- 为函数定义符号不明确的指针参数
- 父类的私有函数会导致对具有相同名称和相似参数的子类中的公共函数的不明确调用
- 在 C++17 中的命名空间和子命名空间中重载运算符是不明确的
- "byte":使用Crypto++和Windows SDK时出现不明确的符号错误
- 错误错误 C2872:"布尔值":kinect.h 的不明确符号
- G++ 错误:重载的"abs(无符号 int)"的调用不明确
- 不明确的符号
- Boost::python带有ACE,C++符号不明确
- 错误:"数组":符号不明确
- Visual C++编译器为不明确的符号提供了错误的行引用
- 使用 python 编译引脚工具的错误包括,得到错误 C2872:'UINT32':不明确的符号
- 嵌套的命名空间和不明确的符号
- 符号错误不明确
- 为不明确的符号获取错误,需要帮助将其删除
- 为什么用整数文字调用重载的 ambig(long) 和 ambig(无符号 long)是不明确的
- Visual Studio 2008 - 错误 C2872:'NPC':不明确的符号
- 函数指针-不明确的符号错误