当前位置: 代码迷 >> 综合 >> C++引用指定头文件中的函数 call of overloaded xxx is ambiguous
  详细解决方案

C++引用指定头文件中的函数 call of overloaded xxx is ambiguous

热度:72   发布时间:2023-12-15 17:19:49.0

1,解决办法是使用namespace。头文件中的函数一般会写明定义在某一个命名空间中的,所以在调用那个函数前,加上 namespace名::函数名就可以了。

#include "opencv2/core.hpp"
#include "opencv2/cudaarithm.hpp"minMaxLoc(errors, NULL, &max_value, NULL, NULL, mask);/* 比如引用了两个头文件,都定义了minMaxLoc这个函数。这时候在main中调用minMaxLoc,在build的时候就会发生overload的问题。报错:/home/xxx/projects/optical_flow/remote/cpp/denseLK_gpu/denselk.cpp:157:57: error: call of overloaded 鈥?minMaxLoc(cv::Mat&, NULL, double*, NULL, NULL, cv::Mat&)鈥? is ambiguousminMaxLoc(errors, NULL, &max_value, NULL, NULL, mask);^
In file included from /home/xxx/projects/optical_flow/remote/cpp/denseLK_gpu/denselk.cpp:13:0:
/usr/local/include/opencv2/cudaarithm.hpp:607:17: note: candidate: void cv::cuda::minMaxLoc(cv::InputArray, double*, double*, cv::Point*, cv::Point*, cv::InputArray)CV_EXPORTS void minMaxLoc(InputArray src, double* minVal, double* maxVal, Point^
In file included from /usr/local/include/opencv2/imgproc.hpp:46:0,from /usr/local/include/opencv2/imgproc/imgproc.hpp:48,from /home/xxx/projects/optical_flow/remote/cpp/denseLK_gpu/denselk.cpp:9:
/usr/local/include/opencv2/core.hpp:817:19: note: candidate: void cv::minMaxLoc(cv::InputArray, double*, double*, cv::Point*, cv::Point*, cv::InputArray)CV_EXPORTS_W void minMaxLoc(InputArray src, CV_OUT double* minVal,^
*/


解决方法是:

1,首先确定你要调用的是哪个头文件中的minMaxLoc函数,比如这里我经过排查确定是要调用opencv2/core.hpp中的。

2,查看你要调用的函数所在的头文件(opencv2/core.hpp),里面可能写了minMaxLoc所在的命名空间,我这里是namspace cv

#ifndef OPENCV_CORE_HPP
#define OPENCV_CORE_HPP#ifndef __cplusplus
#  error core.hpp header must be compiled as C++
#endif#include "opencv2/core/cvdef.h"
#include "opencv2/core/version.hpp"
#include "opencv2/core/base.hpp"
#include "opencv2/core/cvstd.hpp"
#include "opencv2/core/traits.hpp"
#include "opencv2/core/matx.hpp"
#include "opencv2/core/types.hpp"
#include "opencv2/core/mat.hpp"
#include "opencv2/core/persistence.hpp"...namespace cv {...CV_EXPORTS_W void minMaxLoc(InputArray src, CV_OUT double* minVal,CV_OUT double* maxVal = 0, CV_OUT Point* minLoc = 0,CV_OUT Point* maxLoc = 0, InputArray mask = noArray());

3,然后在main中调用minMaxLoc时,在前面加上函数对应的命名空间名称cv,如:

    cv::minMaxLoc(errors, NULL, &max_value, NULL, NULL, mask);

这样就不会报overload的错误了

 

 

参考:https://blog.csdn.net/u013719339/article/details/80221899

  相关解决方案