In article <87hdug7yx2.fsf@abc.abc>, William Xuuu <abc@abc.abc> wrote:[color=blue]
>"John Harrison" <john_andronicus@hotmail.com> writes:
>[color=green][color=darkred]
>>> The answer is to tell the compiler that the friend declaration refers to a
>>> template function. You do that by adding '<T>' or '<>' after operator+.
>>>[/color][/color]
>
>Hmm, it works fine by adding <> or <T> as follows.
>
>//begin class itself
>template <typename T> class Vector_Set
>{
>
>friend Vector_Set<T> operator+<T> (const Vector_Set<T>& s1, const
> Vector_Set<T>& s2);
>};
>
>While, the C++ FAQ didn't add <> or <T> ?!
>
>Then I find it's not allowed to use + as:
>
> a +<int> b;
>
>So ?[/color]
Not sure what you're asking, but perhaps you're looking for
the long-hand version like a.operator+<int>(b);
[color=blue]
>[color=green]
>> Hmm, seems gcc doesn't always handle the <T> form correctly. I would stick
>> with <>.[/color]
>
>Could you explain the differences between <T> and <> ?
>
>And, i find that either adding <T> after pre-declaration or its
>implementation, as:
>
>//pre declarations.
>template <typename T> class Vector_Set;
>template <typename T> Vector_Set<T> operator+<T> (const Vector_Set<T>& s1,
> const Vector_Set<T>& s2);
>
>
>// friends implementation
>template <typename T> Vector_Set<T> operator+<T> (const Vector_Set<T>& s1,
> const Vector_Set<T>& s2)
>{ ... }
>
>
>both would cause same error:
>
>error: partial specialization `operator+<T>' of function template
>
>Why would it happen?[/color]
Because a "primary" template declaration should not mention
it's arguments on its name, which the <T> would do above, but
since it's declared above, the friend is using it in your case,
not declaring it as such.
--
Greg Comeau / Comeau C++ 4.3.3, for C++03 core language support
Comeau C/C++ ONLINE ==>
http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware's Libraries... Have you tried it?