function pointer

A

Ali

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;
}
 
P

puzzlecracker

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.
 
A

Ali

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;
}
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top