friend template error in gcc 4.1

A

abelahcene

Hi, Is it a bug ??
I tried to compile a cpp program which ran correctly on previous
release (sarge debian, gcc compiler 3 ), it gave errors, for the
declaration (even if I omit the symbols <> )

friend ostream & operator << <> (ostream & os, Vector <T> & tab);

for other declaration ( not friend), the + operator, it works !! here
is a complete example with errors at the compilation step.
If I omit the << operator, the program will run
Thank you for help

NOTE: if I declare size public it works!!!!!



It works on previous compiler
-----------------------PROGRAM ------------------

#include <iostream>
using namespace std;
#define SIZE 10

template <class T>
class Vector{
protected:
int size;
T ptrVect[SIZE];
public:
Vector (int);
Vector(int , T a[]);
Vector <T> operator + ( Vector <T> & tab);
T & operator [] (int i);
void print(){
for (int i=0; i < size; i++)
cout <<" "<< ptrVect;
}
friend ostream & operator << <> (ostream & os, Vector <T> & tab);
};
template <class T>
Vector<T>::Vector(int nbre, T a[]){
size = nbre;
for (int i=0; i < size;i++)
ptrVect= a ;
}
template <class T>
Vector<T>::Vector(int nbre){
size = nbre;
}

template <class T>
T & Vector<T>::eek:perator [] (int i){
return ptrVect ;
}
template <class T>
Vector<T> Vector<T>::eek:perator + ( Vector <T> & tab){
Vector<T> v(size);
v.size=size;
for(int i=0; i < size; i++){
v.ptrVect = ptrVect + tab.ptrVect;
}
return v;
}
template <class T>
ostream & operator << (ostream & os, Vector <T>& tab){
for(int i=0; i < tab.size;i++)
os << tab <<" ";
return os;
}
int main(){
int A[]={14, 20,26 }, B[]={9,7,34};
Vector <int> v1(3, A), v2(3,B), v3(3);
v3= v1+v2;
cout << "\n first vector is ";
v1.print();
cout << "\n second one is ";
v2.print();
cout << "\n Their sum is " ;
cout << v3;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top