friend funtion in template klasse



  • in der hpp:

    template < class typ > class vektor{
    private:
    	typ x,y,z;
    public:
    	vektor(typ a, typ b, typ c);
    	friend ostream &operator<<(ostream &os, vektor(typ) &name);
    	friend istream &operator>>(istream &is, vektor(typ) &name);
    };
    

    bekomme leider ne fehlermeldung bei den überladenem >>, <<!
    hab jetzt in einem buch gelesen das es an dem friend liegt.
    wir bekomm ich das denn jetzt grade gebogen?

    in der cpp sind die funktionen so deklariert:

    template < class typ > ostream &operator <<(ostream &os, const vektor &name){
    	...
    return os;
    }
    
    //Eingabe Vektor
    template < class typ > istream &operator >>(istream &is, vektor &name){
    	...
    return is;
    }
    


  • template < class typ > ostream &operator <<(ostream &os, const typename vektor<typ> &name){

    nächstes mal die fehlermeldung mal lesenund evtl so gar posten!? ^^

    bb



  • template < class typ > class vektor{ //line 13
    private:
    	typ x,y,z;
    public:
    	vektor(typ a, typ b, typ c);
    	~vektor();
    	...
    	template < class typ > &operator <<(ostream &os, const vektor<typ> &name); //line 25
    	template < class typ > &operator >>(istream &is, vektor<typ> &name); //line 26
    };
    

    ..\src\vector.hpp:25: error: declaration of 'class typ'
    ..\src\vector.hpp:13: error: shadows template parm 'class typ'
    ..\src\vector.hpp:25: error: expected constructor, destructor, or type conversion before ';' token
    ..\src\vector.hpp:26: error: declaration of 'class typ'
    ..\src\vector.hpp:13: error: shadows template parm 'class typ'
    ..\src\vector.hpp:26: error: expected constructor, destructor, or type conversion before ';' token



  • s.o.


Anmelden zum Antworten