This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: problems with implicit template specialization
- To: Andrey Slepuhin <pooh at msu dot ru>
- Subject: Re: problems with implicit template specialization
- From: Alexandre Oliva <oliva at dcc dot unicamp dot br>
- Date: 08 Oct 1997 07:53:15 -0200
- Cc: egcs-bugs at cygnus dot com
- References: <343B5448.10C26F74@msu.ru>
Andrey Slepuhin writes:
> I have troubles with a following code, which works fine with gcc
> 2.7.2.2:
It works fine because gcc 2.7.2.2 does not comply with the current
(Draft of the) C++ Standard.
> friend T* f(A<T>&);
this declared a friend function, that is not the same as an instance
of the template:
> template <class T> T* f(A<T>& x)
For this to work, you must provide the following declarations before
you define the template class A:
template <typename T>
class A;
template <typename T>
T* f(A<T>& x);
Then, inside the body of template class A, you should refer to:
friend T* f<>(A<T>&);
// or
friend T* f<T>(A<T>&);
> replacing f(y) by f<int>(y) [at invocation point] all works fine.
It shouldn't, since f<T> does not have priviledged access to private
parts of A<T>.
> why I didn't get any errors or warnings about undeclared function
> f(A<int>&)?
Because it was declared inside the body of template class A.
--
Alexandre Oliva
mailto:oliva@dcc.unicamp.br mailto:aoliva@acm.org
http://www.dcc.unicamp.br/~oliva
Universidade Estadual de Campinas, SP, Brasil