簡體   English   中英

超載的召喚是模棱兩可的

[英]Call of overloaded is ambiguous

我有以下編譯器錯誤"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
}

實際上兩個不同的reduceColors函數:聲明的函數,第二個參數是ipl_image_wrapper& ,以及定義的函數,第二個參數是ipl_image_wrapper 讓他們一樣。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM