A simple sample code involving templates, friends and lookup
Paolo Bonzini
bonzini@gnu.org
Thu Jan 17 13:35:00 GMT 2008
>> template <typename T>
>> struct Foo
>> {
>> template <typename Z>
>> friend void func(const Foo &);
>> };
>>
>> void check(const Foo<int> & x)
>> {
>> // Foo<int> weird; // uncomment this line and all works
>>
>> func<int>(x); // <-- ERROR
>> }
>>
>>
>> Tested with gcc 4.0 - 4.3, and all behave the same:
>>
>> "error: 'func' was not declared in this scope"
>>
>> but it works if you uncomment the weird line.
>
> Actually even with the weird line the program is invalid. What are
> you trying to do? ;)
I don't know if it is invalid or not, but with the weird line
uncommented it compiles (like if func was brought into scope).
Paolo
More information about the Gcc
mailing list