global namespace polluted with symbol uchar?

asked 2015-05-14 20:53:33 -0500

Hugues gravatar image

The symbol uchar in defs.h seems to be defined outside the cv namespace, which causes problems if it is also defined in a different namespace:

#include <opencv2/opencv.hpp>

namespace other {
    using uchar = unsigned char;
}
using namespace other;

int main() {
    uchar c = 'a';
    (void)c;
}

// bug_opencv_uchar.cpp(17) : error C2872: 'uchar' : ambiguous symbol
//         could be '...\include\opencv2\hal\defs.h(284) : unsigned char uchar'
//         or       '...\bug_opencv_uchar.cpp(9) : other::uchar'

// Using VC12 with http://sourceforge.net/projects/opencvlibrary/files/opencv-win/3.0.0-rc1/opencv-3.0.0-rc1.exe/download

Isn't this a bug?

The only workaround is to avoid doing "using namespace" on any namespace which defines uchar. If opencv were a good citizen and restricted its definition of uchar to namespace cv, this draconian measure would not be necessary.

edit retag flag offensive close merge delete