Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > function pointer

Reply
Thread Tools

function pointer

 
 
Ali
Guest
Posts: n/a
 
      08-21-2008
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: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;
}

 
Reply With Quote
 
 
 
 
puzzlecracker
Guest
Posts: n/a
 
      08-21-2008
On Aug 21, 7:32*am, Ali <ali.baha...@gmail.com> 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: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.
 
Reply With Quote
 
 
 
 
Ali
Guest
Posts: n/a
 
      08-21-2008
> What's the definition of operator+? Also, provide more *details *on
> namespace cxsc.


Thank you for the response.

The documentation of the interval class is here:

http://www.math.uni-wuppertal.de/org...1interval.html

The namespace cxsc is here:

http://www.math.uni-wuppertal.de/org...spacecxsc.html

Thanks.
 
Reply With Quote
 
Ali
Guest
Posts: n/a
 
      08-22-2008
On Aug 21, 11:16 pm, Thomas Maeder <mae...@glue.ch> wrote:
> Ali <ali.baha...@gmail.com> 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: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;
}





 
Reply With Quote
 
Ali
Guest
Posts: n/a
 
      08-22-2008
Gotcha. (What is Koenig lookup?)

Just has to insert line:

cxsc::interval cxsc:perator+(const cxsc::interval&, const
cxsc::interval&) throw() ;

before main().

Explanation here:

http://h21007.www2.hp.com/portal/sit...10275d6e10RCRD

http://womble.decadentplace.org.uk/c...ax-errors.html

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
function pointer and pointer to function prashant.khade1623@gmail.com C Programming 3 04-11-2008 07:30 AM
diffrence between "function pointer" and "pointer to a function" murgan C Programming 6 12-21-2005 06:01 AM
Passing pointer to template function as argument to pointer to template function Vijai Kalyan C++ 4 11-08-2005 07:53 PM
pointer to member function and pointer to constant member function Fraser Ross C++ 4 08-14-2004 06:00 PM
function pointer and member function pointer question glen stark C++ 2 10-10-2003 01:41 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57