Funktionstemplate als friend eines Klassentemplates



  • Hallo,

    ich habe ein Klassentemplate Det_Manip und möchte das Funktionstemplate

    template<class T> ostream& operator<<(ostream& s, const Bound_Det_Manip<T>& bdm);
    

    als friend von Det_Manip deklarieren:

    #ifndef TEMP_H_
    #define TEMP_H_
    
    ...
    
    template<class T> class Bound_Det_Manip;
    
    template<class T> ostream& operator<<(ostream& s, const Bound_Det_Manip<T>& bdm);
    
    template<class T> class Det_Manip
    {
    	friend ostream& operator<<<T>(ostream& s, const Bound_Det_Manip<T>& bdm);
    private:
    	int m_level;
    public:
    	explicit Det_Manip(int level) : m_level(level) { }
    	Bound_Det_Manip<T> operator()(const T* n) const;
    };
    
    template<class T> class Bound_Det_Manip
    {
    	...
    };
    
    ...
    
    #endif
    

    Das kompiliert so ohne Warnmeldungen auszugeben. Wenn ich allerdings in Zeile 14

    friend ostream& operator<<<T>(ostream& s, const Bound_Det_Manip<T>& bdm);
    

    durch

    friend ostream& ::operator<<(ostream& s, const Bound_Det_Manip<T>& bdm);
    

    ersetze, erhalte ich die Compilermeldung

    ../src/temp.h:18: warning: friend declaration ‘std::ostream& operator<<(std::ostream&, const Bound_Det_Manip<T>&)’ declares a non-template function
    ../src/temp.h:18: warning: (if this is not what you intended, make sure the function template has already been declared and add <> after the function name here) -Wno-non-template-friend disables this warning

    und das Programm macht dasselbe wie vorher.

    Trotz Lektüre von 8.4.1 "Friend Functions" des Josuttis (C++ Templates) verstehe ich nicht, was hier das Problem ist. Kann das jemand erklären?


Anmelden zum Antworten