function pointer

Discussion in 'C++' started by Ali, Aug 21, 2008.

  1. Ali

    Ali Guest

    This code below works with M$ VS2005 but fails with g++ 4.1.3.
    However, the unary operation works with g++ as well.

    The interval class is at http://xsc.de but everything is declared as
    it should be.

    The error message of g++ is:

    main.cpp:9: error: no matches converting function ‘operator+’ to type
    ‘class cxsc::interval (*)(const class cxsc::interval&, const class
    cxsc::interval&)’
    [...]
    candidates are: cxsc::interval cxsc::eek:perator+(const cxsc::interval&,
    const cxsc::interval&)

    -------------------------------------------------------------------------------------
    #include "interval.hpp"
    using namespace cxsc;

    int main() {

    typedef interval (*bin_op) (const interval&, const interval&);

    bin_op Add;
    Add = operator+;

    typedef interval (*un_op) (const interval& );

    un_op Exp;
    Exp = exp;


    return 0;
    }
     
    Ali, Aug 21, 2008
    #1
    1. Advertising

  2. On Aug 21, 7:32 am, Ali <> wrote:
    > This code below works with M$ VS2005 but fails with g++ 4.1.3.
    > However, the unary operation  works with g++ as well.
    >
    > The interval class is athttp://xsc.debut everything is declared as
    > it should be.
    >
    > The error message of g++ is:
    >
    > main.cpp:9: error: no matches converting function ‘operator+’ to type
    > ‘class cxsc::interval (*)(const class cxsc::interval&, const class
    > cxsc::interval&)’
    > [...]
    > candidates are: cxsc::interval cxsc::eek:perator+(const cxsc::interval&,
    > const cxsc::interval&)
    >
    > -------------------------------------------------------------------------------------
    > #include "interval.hpp"
    > using namespace cxsc;
    >
    > int main() {
    >
    >         typedef interval (*bin_op) (const interval&, const interval&);
    >
    >         bin_op Add;
    >         Add = operator+;
    >
    >         typedef interval (*un_op) (const interval& );
    >
    >         un_op Exp;
    >         Exp = exp;
    >
    >         return 0;
    >
    > }
    >
    >


    What's the definition of operator+? Also, provide more details on
    namespace cxsc.
     
    puzzlecracker, Aug 21, 2008
    #2
    1. Advertising

  3. Ali

    Ali Guest

    Ali, Aug 21, 2008
    #3
  4. Ali

    Ali Guest

    On Aug 21, 11:16 pm, Thomas Maeder <> wrote:
    > Ali <> writes:
    >
    > > The documentation of the interval class is here:

    >
    > Please post a minimal (i.e. just enough code, not more and not less)
    > that allows others to copy & paste & compile & see what you are seeing.


    Quite unfortunately all my minimal codes compile and run without any
    problems with g++ (with MS VS2005 i get: error C2440: '=' : cannot
    convert from 'foo (__cdecl *)(const foo &)' to 'foo (__cdecl *)(const
    foo &)'
    Incompatible calling conventions for UDT return value), it is strange
    that with the original code VS2005 work properly). Please see the
    minimal code at the end of this message.

    I do not understand the original error message:

    main.cpp:9: error: no matches converting function ‘operator+’ to type
    ‘class cxsc::interval (*)(const class cxsc::interval&, const class
    cxsc::interval&)’
    [...]
    candidates are: cxsc::interval cxsc::eek:perator+(const cxsc::interval&,
    const cxsc::interval&)

    What is the compiler's problem? What is the different between my
    declaration and the candidate?

    Let me emphasize that the minimal code below compiles with g++. I also
    tried to encapsulate the class into a namespace but still worked.

    ------------------------------------------------------------

    class foo {

    public:

    friend foo operator+(const foo&, const foo&);

    friend foo operator-(const foo& );
    };

    foo operator+(const foo&, const foo&) {

    return foo();
    }

    foo operator-(const foo&) {

    return foo();
    }

    int main() {

    foo (*Add) (const foo&, const foo&);

    Add = operator+;

    foo (*Neg) (const foo& );

    Neg = operator-;

    return 0;
    }
     
    Ali, Aug 22, 2008
    #4
  5. Ali

    Ali Guest

    Ali, Aug 22, 2008
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. glen stark
    Replies:
    2
    Views:
    727
    Ron Natalie
    Oct 10, 2003
  2. Fraser Ross
    Replies:
    4
    Views:
    1,094
    Fraser Ross
    Aug 14, 2004
  3. murgan
    Replies:
    6
    Views:
    4,948
    Thad Smith
    Dec 21, 2005
  4. Vijai Kalyan
    Replies:
    4
    Views:
    745
    Vijai Kalyan
    Nov 8, 2005
  5. Replies:
    3
    Views:
    329
    Philip Potter
    Apr 11, 2008
Loading...

Share This Page