C++ 不明确的符号错误?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9475999/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Ambiguous symbol error?
提问by Haxify
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;
}
}
I've never gotten this error and this is frustrating.
我从来没有遇到过这个错误,这令人沮丧。
回答by FatalError
Your variable max
conflicts with std::max()
. Try using a different name and it ought to fix that error.
您的变量max
与std::max()
. 尝试使用不同的名称,它应该可以修复该错误。
回答by Mona Jalal
I had the same problem when using Intel RealSense 3D SDK
in C++
. I had a hand.cpp
and hand.h
in my own code and when I had using namespace Intel::RealSense;
it happen to be a conflict. In order to fix it, I removed using namespace Intel::RealSense;
and added PXC to each class name related to the RealSense SDK.
Here are some example of new changes:
#
我使用的时候有同样的问题Intel RealSense 3D SDK
在C++
。我有一个hand.cpp
andhand.h
在我自己的代码中,当我遇到using namespace Intel::RealSense;
它时发生了冲突。为了修复它,我删除using namespace Intel::RealSense;
并添加了 PXC 到与实感 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;
and here's what the old code looked like:
这是旧代码的样子:
#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;
After the changes, I didn't receive the following error anymore.
更改后,我不再收到以下错误。
Severity? ? Code? ? Description Project File? ? Line? ? Suppression State
Error ? C2872 ? 'Hand': ambiguous symbol? ? OpenARK-SDK c:\openark\Object3D.h
回答by Thomas
I think the problem is not std::max()
but these horrible #define's
in minwindef.h
:
我认为问题不在于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 */
Use #define NOMINMAX
in your project settings or stdafx.h
.
使用#define NOMINMAX
在您的项目设置或stdafx.h
。