Re: different friend functions behaviour

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx> 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

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux