【问题标题】:What can cause ambiguous symbol errors on one computer and not another?什么会导致在一台计算机上而不是另一台计算机上出现模棱两可的符号错误?
【发布时间】:2012-04-09 20:15:34
【问题描述】:

我正在使用 Visual Studio 2010 处理 C++ 代码。该项目及其所有内容已由其他人编写,并复制到共享驱动器上。当创建者在他的计算机上构建它时,它工作正常。当我尝试构建解决方案时,我得到了一大堆这些错误

error C2872: '<lambda0>' : ambiguous symbol could be 
 '[File].cpp(66) : anonymous-namespace'::<lambda0>' or 
 '[Different file].h(549) : `anonymous-namespace'::<lambda0>'. 

这是一个被认为是错误的行的示例:

std::pair<int, std::pair<int, Point>> b) -> bool { return (a.second.second < b.second.second ); });

似乎错误总是以'});'结尾的行发生。在这里展示的完整代码相当庞大,并且它可以在其他计算机上运行,​​所以大概是我的设置或其他什么问题。有人可以大胆猜测一下它们可能是什么吗?

【问题讨论】:

  • 你的编译器支持c++11吗?
  • VS 的补丁级别相同?
  • 谢谢,STATUS_ACCESS_DENIED(还有 juanchopanza - 这帮助我弄清楚了 lambda 是什么)。原来是我的版本有问题 - 我错过了修复 this 错误的补丁。

标签: c++ visual-studio-2010 compiler-errors


【解决方案1】:

不确定你是否看到过这个,但根据 MSDN 页面的编译器错误:

C2872 can occur if a header file includes a using Directive (C++), and a subsequent header file is #include'd and contains a type that is also in the namespace specified in the using directive. Specify a using directive only after all your header files are specified with #include.

MSDN Page

【讨论】:

    【解决方案2】:

    我也遇到过同样的符号不明确的问题。对我来说,事实证明我使用了两个功能相同但定义明显不同的命名空间。我必须停止使用其中一个命名空间,这解决了这个问题。

    举个例子:

    using namespace cv;
    using namespace boost::accumulator;
    accumulator_set<double, stats<tag::mean, tag::variance> > acc;
    double meanval = mean (acc);
    

    这将通过编译错误:error C2872: 'mean' : ambiguous symbol 这是因为命名空间 cv 和 boost::accumulator 具有相同的函数“mean”

    希望对你有帮助

    【讨论】:

      【解决方案3】:

      我也遇到了同样的问题 安装 VS2010 SP1 为我解决了模棱两可的 anonymous-namespace'::&lt;lambda0&gt; 问题。没有 SP1 的 VS2010 有 lambdas 的问题。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-09-08
        • 2011-03-30
        • 1970-01-01
        • 1970-01-01
        • 2016-04-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多