模糊符号错误?

时间:2012-02-28 03:29:14

标签: c++ compiler-errors

int ii, maxnum;  
for(ii=1; ii<=num-1; ii++) {  
    if(count[ii]>max) {  // the part where I get C2872 Ambiguous Symbol error  
        max = count[ii]; // the part where I get C2872 Ambiguous Symbol error  
        maxnum = ii;  
    }  
}  

我从来没有得到过这个错误,这令人沮丧。

3 个答案:

答案 0 :(得分:17)

您的变量maxstd::max()冲突。尝试使用其他名称,它应该修复该错误。

答案 1 :(得分:0)

Intel RealSense 3D SDK中使用C++时遇到了同样的问题。我自己的代码中有hand.cpphand.h,当我using namespace Intel::RealSense;时恰好是冲突。为了解决这个问题,我删除了using namespace Intel::RealSense;并将PXC添加到与RealSense SDK相关的每个类名中。 以下是一些新变化的示例: #

include "RealSense/SenseManager.h"
#include "RealSense/SampleReader.h"
#include "util_render.h"
#include "Visualizer.h"
#include <iostream>
using namespace std;
//using namespace Intel::RealSense;
PXCSenseManager *pp = PXCSenseManager::CreateInstance();
PXCCapture::Device *device;
PXCCaptureManager *cm;

以下是旧代码的样子:

#include "RealSense/SenseManager.h"
#include "RealSense/SampleReader.h"
#include "util_render.h"
#include "Visualizer.h"
#include <iostream>
using namespace std;
using namespace Intel::RealSense;
SenseManager *pp = SenseManager::CreateInstance();
Capture::Device *device;
CaptureManager *cm;

更改后,我不再收到以下错误。

Severity    Code    Description Project File    Line    Suppression State
Error   C2872   'Hand': ambiguous symbol    OpenARK-SDK c:\openark\Object3D.h 

答案 2 :(得分:0)

我认为问题不是std::max(),而是#define's中的这些可怕的minwindef.h

#ifndef NOMINMAX

  #ifndef max
  #define max(a,b)            (((a) > (b)) ? (a) : (b))
  #endif

  #ifndef min
  #define min(a,b)            (((a) < (b)) ? (a) : (b))
  #endif

  #endif  /* NOMINMAX */

在项目设置中使用#define NOMINMAX或在stdafx.h中使用。

相关问题