On Fri, Dec 15, 2006 at 04:24:04PM -0800, Dawser Stevens wrote:
> The following code can be compiled with every other
> compiler I have tried (including gcc 4.0 apart from
> several commercial ones), but, unfortunately, gcc
> 4.1.2 outputs this:
>
> overload.cpp: In function "int main()":
> overload.cpp:18: error: no matches converting function
> "f" to type "void (*)(class A&, const int&)"
> overload.cpp:4: error: candidates are: void f(A&,
> const int&)
> overload.cpp:5: error: void f(A&)
I think the problem is tweaked by the fact that the first declarations
of the "f" functions are in a friend statement. If I add
class A;
void f(A &a, const int &b);
void f(A &a);
before the class, the code compiles.
> This is the code:
>
> -------------------------------------------------
> class A {
> public:
> int val(void) { return x; }
> friend void f (A &a, const int &b) { a.x = b; }
> friend void f (A &a) { a.x = 0; }
> private:
> int x;
> };
>
> typedef void (*fptr) (A &a, const int &b);
>
> int main (void)
> {
> A a;
> int b = 1;
> fptr g;
> g = f;
> g (a, b);
> return a.val();
> }
> --------------------------------------------------
> I suspect the problem can create big compatibility
> problems with already written math code (e.g.
> matrix/vector operations), and Ubuntu is currently
> shipping this version, potentially affecting many,
> many users.
The standard compiler on Fedora Core 5 (4.1.1 + patches) also shows
this problem, yet they built a distro with it, so I think that it's
not a huge issue.