different friend functions behaviour
Fabio Tesser
fabio.tesser@gmail.com
Wed Apr 8 09:38:00 GMT 2009
Thanks for reply Ian.
The Argument Dependent Lookup should be active even inside a template class?
If I try put the friend function inside a template, g++ (version 4.3.2)
gives me the following error:
$ cat test_template_friend_function.cpp
////////////////////////////////////
class test {
public:
friend void ftest2(test x) {
}
};
template <class T>
class simple_template
{
public:
void ftest3(T){
ftest2(test());
}
};
int main(int argc, char *argv[]) {
simple_template<int> a;
a.ftest3(0);
}
/////////////////////////////////////////
$ g++ test_template_friend_function.cpp
test_template_friend_function.cpp: In member function âvoid
simple_template<T>::ftest3(T) [with T = int]â:
test_template_friend_function.cpp:18: instantiated from here
test_template_friend_function.cpp:12: error: no matching function for
call to âftest2(test)â
The same code compiles without errors with gcc version 4.2.4.
In your opinion what is the correct behavior?
Thanks
Fabio
On 04/07/2009 06:44 PM, Ian Lance Taylor wrote:
> Fabio Tesser <fabio.tesser@gmail.com> writes:
>
>
>> The difference between the two friend functions is that the first has
>> not any test class as argument while the second has a test class as
>> argument.
>>
>> Is this the right behaviour?
>>
>
> Yes, this is correct. This is Argument Dependent Lookup, also known as
> Koenig lookup.
>
> http://en.wikipedia.org/wiki/Argument_dependent_lookup
>
> Ian
>
More information about the Gcc-help
mailing list