Chapter Contents

Previous

Next
746

746



WARNING: Friend declaration does not declare a template specialization.


Explanation


Explanation

A friend declaration in a template class uses the names of template type formals, but the declaration designates a non-template function. When used with older compilers, such a construct was generally used to refer to a specialization of a template function. However the C++ standard treats the construct as a declaring a non-template function unless the function declarator has explicit template arguments or has an explicit scope specifier. With an explicit scope specifier, a template specialization is found if there was not a previous non-template declaration. For example:

template <class T> class C;
template <class T> C<T> operator+( const C<T>&, const C<T>& );
template <class T> C <T> operator-( const C<T>&, const C<T>& );
template <class T> class C {
    // non-template declaration, the warning is issued
    friend C<T> operator+( const C<T>&, const C<T>& );
    // scoped declaration finds a template specialization 
    friend C<T> (::operator+)( const C<T>&, const C<T>& );
    // template specialization, using explicit template arguments
    friend C<T> operator-<>( const C<T>&, const C<T>& );
  private:
    // . . .
};

The warning is not issued if the friend is defined in the template class body. With the NOTMPLFUNC option, the old interpretation of the first friend declaration is used and the warning will not be issued.


Chapter Contents

Previous

Next

Top of Page

Copyright © 2004 by SAS Institute Inc., Cary, NC, USA. All rights reserved.