|
-
June 29th, 2006, 05:19 PM
#1
new way of overloading operators in templates??
First of all, this code does compile with g++ 3.3.5. But with g++ 4.0.2 it gives me a few errors. g++ enters the #else portion. The _MSC_VER is meant to be able to compile it in VC++ 5
Code:
#ifdef _MSC_VER
friend CMatriz<TG> operator+(const TG &op1,const CMatriz<TG> op2); // objeto TG + CMatriz
friend CMatriz<TG> operator+(const double &op1,const CMatriz<TG> &op2); // constante + CMatriz
#else /*Next line is 64*/
friend CMatriz<TG> operator+ <>(const TG &op1,const CMatriz<TG> &op2); // objeto TG + CMatriz
friend CMatriz<TG> operator+ <>(const double &op1,const CMatriz<TG> &op2); // constante + CMatriz
#endif
The compiler says:
Matriz.h:64: error: declaration of 'operator+' as non-function
This error happens too with another operators. However with the <<:
Code:
#ifdef _MSC_VER
friend ostream &operator<<(ostream &os,const CMatriz<TG> &op);
#else /*Next line is 87*/
friend ostream &operator<< <>(ostream &os,const CMatriz<TG> &op);
#endif
The compiler gives a different error:
Matriz.h:87: error: template-id 'operator<< <>' for std::basic_ostream<char, std::char_traits<char> >& operator<<(std::basic_ostream<char, std::char_traits<char> >&, const CMatriz<CComplejo>&)' does not match any template declaration
Any clues as to how should these be declared?
int i;main(){for(;i["]<i;++i){--i;}"];read('-'-'-',i+++"hell\
o, world!\n",'/'/'/'));}read(j,i,p){write(j/p+p,i---j,i/i);}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|