funktionszeiger auf überladene funktionen



  • ich bin im moment etwas verwirrt, ich wollte eine funktion aus cmath wie folgt binden:

    phoenix::bind(&std::pow(double,double))(/*...*/)
    

    der gcc gab mir daraufhin folgenden fehler:

    error: no matching function for call to `pow(<type error>, <type error>)'
    note: candidates are: double std::pow(double, double)

    ich weis, dass man überladenen funktionen anders behandeln musste,normal reicht ja nur der name, aber so wies oben steht scheints wohl nicht zu klappen, leider hat mir die suche hier aufm board nichtmehr den gesuchten thread gebracht, weshalb ich diese frage wohl nochmal stellen muss 😞

    weis jemand, wie die korrekte syntax lautet?



  • Der g++ schluck das hier

    #include<iostream>
    using namespace std;
    void foo(int)
    {
      cout<<"foo(int)"<<endl;
    }
    void foo(int, int)
    {
      cout<<"foo(int,int)"<<endl;
    }
    
    typedef void(*Func1)(int);
    typedef void(*Func2)(int,int);
    
    int main()
    {
      Func1 func1 = static_cast<Func1>(&foo);
      Func2 func2 = static_cast<Func2>(&foo);
      func1(1);
      func2(1,2);
    }
    

    Inwiefern das jetzt standard conform ist weis ich aber nicht.



  • Ein cast sollte meines wissens nach standardkonform sein.



  • der cast funktioniert perfekt 🙂

    danke 🙂


Anmelden zum Antworten