This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: problems with implicit template specialization


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]