I’m getting confused about the scope of ‘using namespace’ declarations… hoping someone can clear this up for me!
I’m using two libraries (OpenCV and Ogre3D). I have two cpp files, one uses exclusively OpenCV (PoseEstimator.cpp) and the other exclusively Ogre3D (OgreLogic.cpp).
The top of OgreLogic.cpp looks like this:
#include "stdafx.h"
#include "PoseEstimator.h"
#include "OgreLogic.h"
using namespace Ogre;
And the top of PoseEstimator.cpp looks like this:
#include "StdAfx.h"
#include "PoseEstimator.h"
using namespace cv;
using namespace std;
This ‘using namespace cv’ is the only occurrence in the whole project (I double checked by doing a search). The are no ‘using namespace’s in headers, only ever in cpp files.
However, when compiling OgreLogic.cpp I get ambiguity errors, e.g.:
cxmat.hpp(3465) : error C2872: ‘uchar’
: ambiguous symbol 1> could be
‘d:\libraries\opencv2.1\include\opencv\cxtypes.h(154)
: unsigned char uchar’ 1> or
‘d:\libraries\ogresdk\include\ogre\OgrePrerequisites.h(106)
: Ogre::uchar’
I seem to be misunderstanding something, because I think this should be OK?
Any help greatly appreciated!
Thanks,
Jack
It looks like what is happening is you have a line declaring a
uchar, e.g.uchar x = 12or something. At the top of your file, you’ve specified that you’re using the Ogre namespace. The compiler is running into a problem determining whichucharyou’re using – the cxtypes.h one or the Ogre::uchar.Try taking out the
using namespace Ogre;and do your function calls asOgre::doStuff()to remove ambiguity.