[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: function pointer
From: |
Ali |
Subject: |
Re: function pointer |
Date: |
Thu, 21 Aug 2008 18:19:23 -0700 (PDT) |
User-agent: |
G2/1.0 |
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::operator+(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;
}