This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Overload resolution compilation error


> The function template `std::make_pair<>()' is an example.
> You can directly call it without <>.
> Since &print is not a call expression, C++ compilers cannot determine it 
> by
> function arguments.

You're right, I forgot that rather trivial example. But what I'm trying to 
achieve is the correct resolution when we don't have the function's 
parameters, as when we get the address of the function. Right now I have the 
c++ standard here, and in section 13.1 (over.over, or "Address of overloaded 
function"), the paragraph 4 says:

"If more than one function is selected, any function template 
specializations in the set are eliminated if the
set also contains a non-template function, and any given function template 
specialization F1 is eliminated if

the set contains a second function template specialization whose function 
template is more specialized than

the function template of F1 according to the partial ordering rules of 
14.5.5.2. After such eliminations, if

any, there shall remain exactly one selected function."


If I understand this correctly, when we have the following declarations:

template <class T> void foo() {}
void foo() {}

The overload set for "&foo" at first contains all "void foo<T>()"  and "void 
foo()". Then, because of the presence of the latter, the former should be 
eliminated. In the end, only "void foo()" remains, and we have no ambiguity.

> This problem can be also reduced to this one:
> ==========
> void foo() { }
> void foo(int) { }
>
> int main()
> {
>        &foo;
> }
> ==========

This is different because there's no function template involved.

Regards,
Rodolfo Lima. 




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]