我有以下编译器错误:"call of overloaded ‘reduceColors(ipl_image_wrapper&, ipl_image_wrapper&, int)’ is ambiguous"
我有一个IplImage(DrawingDetection.h)的包装类:
#include <opencv2/opencv.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/objdetect/objdetect.hpp>
#include <opencv2/features2d/features2d.hpp>
#include <boost/shared_ptr.hpp>
#include "Utils.h"
class ipl_image_wrapper
{
public:
typedef boost::shared_ptr< IplImage > ipl_image_ptr_t;
ipl_image_wrapper() {}
ipl_image_wrapper( IplImage* img ) : _img( img, ipl_deleter ) {}
IplImage* get() { return _img.get(); }
const IplImage* get() const { return _img.get(); }
private:
static void ipl_deleter( IplImage* ipl_img )
{
//some code
}
ipl_image_ptr_t _img;
};
我有以下功能(Utils.h):
#include "DrawingDetection.h"
int calculateHomogeneity(const ipl_image_wrapper &img, Factor & factor);
void reduceColors(const ipl_image_wrapper &img, ipl_image_wrapper &out, int levels);
int calculateCComponentsSize(const ipl_image_wrapper &img, Factor &factor);
此功能没有其他声明(!)。我没有超负荷。
源代码带错误(Utils.cpp):
#include <boost/shared_ptr.hpp>
#include "Utils.h"
int calculateCComponentsSize(const ipl_image_wrapper img, Factor &factor)
{
// some calculations
}
void reduceColors(const ipl_image_wrapper &img, ipl_image_wrapper out, int levels)
{
// some calculations
}
int calculateHomogeneity(const ipl_image_wrapper &img, Factor & factor)
{
// some calculations
}
void getFactorsOfImage( const ipl_image_wrapper &image, Factor& factor )
{
ipl_image_wrapper gray = cvCreateImage( cvGetSize ( image.get() ), IPL_DEPTH_8U, 1);
// some calculations
calculateHomogeneity( gray, factor ); // ok
reduceColors( gray, gray, 20 ); // ambiguity !!
int n1 = calculateCComponentsSize( gray, factor );// ambiguity !!
reduceColors( gray, gray, 8 );// ambiguity !!
int n2 = calculateCComponentsSize( gray, factor );// ambiguity !!
// some calculations
}
calculateHomogeneity(...)函数与其余函数之间的差异是什么?他们有一个类似的参数列表。编译器发现歧义的地方?
修改
声明功能顺序非常重要。
源代码没有错误(Utils.cpp):
#include <boost/shared_ptr.hpp>
#include "Utils.h"
void getFactorsOfImage( const ipl_image_wrapper &image, Factor& factor )
{
ipl_image_wrapper gray = cvCreateImage( cvGetSize ( image.get() ), IPL_DEPTH_8U, 1);
// some calculations
calculateHomogeneity( gray, factor ); // ok
reduceColors( gray, gray, 20 ); // ambiguity !!
int n1 = calculateCComponentsSize( gray, factor );// ambiguity !!
reduceColors( gray, gray, 8 );// ambiguity !!
int n2 = calculateCComponentsSize( gray, factor );// ambiguity !!
// some calculations
}
// After getFactorsOfImage function
int calculateCComponentsSize(const ipl_image_wrapper img, Factor &factor)
{
// some calculations
}
void reduceColors(const ipl_image_wrapper &img, ipl_image_wrapper out, int levels)
{
// some calculations
}
int calculateHomogeneity(const ipl_image_wrapper &img, Factor & factor)
{
// some calculations
}
答案 0 :(得分:4)
实际上是两个不同的reduceColors
函数:声明的函数,第二个参数是ipl_image_wrapper&
,以及定义的函数,其第二个参数是{{1 }}。让他们一样。