[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [g++-4.1] Strange problem with overloading
From: |
Pierre Barbier de Reuille |
Subject: |
Re: [g++-4.1] Strange problem with overloading |
Date: |
Tue, 13 Jun 2006 16:34:53 +0100 |
User-agent: |
Thunderbird 1.5.0.2 (X11/20060516) |
Armel Asselin wrote:
>> I have a strange problem with recent g++ while trying to get a pointer
>> on an overloaded function.
>>
>> To extract one specific version of the overloaded function I tried :
>>
>> float ( *v2d_cross )( const Vector2& , const Vector2& ) = cross;
>>
>> But then I get this error:
>>
>> src/wrappers/export_vertex.cpp|120| error: no matches converting
>> function 'cross' to type 'float (*)(const class Vector2&, const class
>> Vector2&)'
>> src/utils/amap_util_vector.h|236| error: candidates are: float
>> cross(const Vector2&, const Vector2&)
>> src/utils/amap_util_vector.h|514| error: Vector3
>> cross(const Vector3&, const Vector3&)
>
> don't know if you could ever get that to work, but at least i'm sure it does
> not work with most c++ compilers: there is no selection of a function
> through a 'to-be-casted-to' rule, to use pointers to members/pointers to
> function, you must have different names: you cannot 'overload'. Calling
> directly disambiguates/works because you have tangible argument to
> disambiguate. But casting does not give these arguments so the compiler
> cannot choose.
>
> Armel
>
>
However, that's the recommended way to do for Boost.Python overloading :
http://boost.org/libs/python/doc/tutorial/doc/html/python/functions.html#python.overloading
And I used it for more than two years without problem.
Furthermore, according to the ISO standard C++ (ยง13.4 - Address of an
overloaded function):
"A use of an overloaded function name without arguments is resolved in
certain contexts to a function, a pointer to function or a pointer to
member function for a specific function from the overload set. A func-
tion template name is considered to name a set of overloaded functions
in such contexts. The function selected is the one whose type matches
the target type required in the context. The target can be [...] an
explicit type conversion."
So, as far as I understand it should work, isn't it ?
Pierre