This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: different friend functions behaviour
- From: Fabio Tesser <fabio dot tesser at gmail dot com>
- To: Ian Lance Taylor <iant at google dot com>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Wed, 08 Apr 2009 11:38:44 +0200
- Subject: Re: different friend functions behaviour
- References: <49DB7311.10208@gmail.com> <m3d4bo5s6u.fsf@google.com>
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