Salve a tutti
volevo chiedere delucidazioni in merito a un errore che ottengo quando specifico il tipo all interno delle parentesi <> di una dichiarazione di una funzione friend di un template di classe ...
posto un po di codice che e` meglio . ..
i problemi sono (o meglio le perplessita`) riguardano l'overload degli operatori + e * .. in particolare nell' operatore + se metto il tipo <mType> ricevo un errore :codice:template<typename mType> Matrix<mType> operator+(const Matrix<mType>& ,const Matrix<mType>&); template<typename mType> Matrix<mType> operator*(const Matrix<mType>&, const Matrix<mType>&); template<class mType> class Matrix { friend std::ostream& operator<< <mType>(std::ostream& , Matrix<mType>& ); friend std::ostream& operator<< <mType>(std::ostream& , const Matrix<mType>& ); friend Matrix<mType> operator+ <>( const Matrix<mType>& , const Matrix<mType>& ); friend Matrix<mType> operator* <mType>(const Matrix<mType>& ,const Matrix<mType>& ); public: inline Matrix(unsigned int = 3, unsigned int = 3 ); // 3x3 as defaulf matrix inline Matrix(unsigned int, unsigned int, mType ); // constructor with initialization inline Matrix( const Matrix<mType>& ); // copy constructor ~Matrix(); inline bool isEmpty()const { return empty_ ; } inline bool allocate( unsigned int , unsigned int ); void print( unsigned int = 5 , unsigned int = 3)const ; // weight and precision as defaul .. void Rand(); void Rand(unsigned int , unsigned int ); void trasp(); inline unsigned int getRowSize()const{ return row_ ;} inline unsigned int getColumnSize()const{ return column_ ;} inline vector<unsigned int> size()const; inline mType& operator()(unsigned int , unsigned int )const; # include "proxy.H" inline Proxy operator[]( unsigned int i ){ return Proxy(*this,i); } Matrix<mType>& operator=( const Matrix<mType>& ); inline void setEmpty(bool t){ empty_ = t ; } template<typename T> Matrix<mType>& operator^(const T); bool operator==(const Matrix<mType>& ); private: unsigned int row_ ; unsigned int column_; mType ** mPtr_ ; // utility function bool isAllocated_; bool empty_; inline bool allocate_(); bool initialize_( mType &) ; };
che non ottengo invece nel caso dell'operatore * pur specificando il tipo come potete vedere ..codice:n file included from /usr/include/c++/4.4/bits/stl_algobase.h:67, from /usr/include/c++/4.4/bits/char_traits.h:41, from /usr/include/c++/4.4/ios:41, from /usr/include/c++/4.4/ostream:40, from /usr/include/c++/4.4/iostream:40, from main.C:1: /usr/include/c++/4.4/bits/stl_iterator_base_types.h: In instantiation of ‘std::iterator_traits<double>’: /usr/include/c++/4.4/bits/stl_iterator.h:96: instantiated from ‘std::reverse_iterator<double>’ matrix.H:35: instantiated from ‘Matrix<double>’ main.C:24: instantiated from here /usr/include/c++/4.4/bits/stl_iterator_base_types.h:127: error: ‘double’ is not a class, struct, or union type /usr/include/c++/4.4/bits/stl_iterator_base_types.h:128: error: ‘double’ is not a class, struct, or union type /usr/include/c++/4.4/bits/stl_iterator_base_types.h:129: error: ‘double’ is not a class, struct, or union type /usr/include/c++/4.4/bits/stl_iterator_base_types.h:130: error: ‘double’ is not a class, struct, or union type /usr/include/c++/4.4/bits/stl_iterator_base_types.h:131: error: ‘double’ is not a class, struct, or union type
ovviamente nelle definizioni delle funzioni (come nelle foward declararation) ovviamente non uso le parentesi <> .. qualcuno mi aiuta a capire il perche ?

 
			
			 
			 
					
					
					
						 Rispondi quotando
  Rispondi quotando .. ma potresti darmi anche una spiegazione ?
 .. ma potresti darmi anche una spiegazione ?
						 
						 
			