boost::function und einfache Funktionspointer: ambigous overload



  • Hi,

    wenn ich eine Funktion überlade, so dass sie verschiedene boost::function argumente nehmen kann:

    class Foo {
    public:
         void bar(boost::function<void(int)> func);
         void bar(boost::function<void(float)> func);
         void bar(boost::function<void(const std::vector<float>&)> func);
    }
    

    und dann versuche, sie mit einem "dummen" Funktionpointer aufzurufen

    void baz(float f) { std::cout << "float :" << f << std::endl; }
    Foo foo;
    foo.bar(&baz);
    

    Erhalte ich folgende Fehlermeldung von gcc

    error: call of overloaded ‘bar(void (*)(float))’ is ambiguous 
    note: candidates are: void Foo::bar(boost::function<void(int)>) 
    note: void Foo::bar(boost::function<void(float)>) 
    note: void Foo::bar(boost::function<void(const std::vector<float, std::allocator<float> >&)>)
    

    Den ersten könnte ich mir ja noch erklären (float lässt sich ja nach int konvertieren), aber wieso versucht der ein void()(float) in einen void()(const std::vector<float>&) zu konvertieren??

    Philipp




Anmelden zum Antworten