Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > friend template error in gcc 4.1

Reply
Thread Tools

friend template error in gcc 4.1

 
 
abelahcene@gmail.com
Guest
Posts: n/a
 
      05-22-2007
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[i];
}
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[i]= a [i];
}
template <class T>
Vector<T>::Vector(int nbre){
size = nbre;
}

template <class T>
T & Vector<T>:perator [] (int i){
return ptrVect [i];
}
template <class T>
Vector<T> Vector<T>:perator + ( Vector <T> & tab){
Vector<T> v(size);
v.size=size;
for(int i=0; i < size; i++){
v.ptrVect[i] = ptrVect[i] + tab.ptrVect[i];
}
return v;
}
template <class T>
ostream & operator << (ostream & os, Vector <T>& tab){
for(int i=0; i < tab.size;i++)
os << tab[i] <<" ";
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;
}

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Declaring a template class with two template params a friend in anon-template class A L C++ 1 08-25-2010 07:25 AM
template template parameters with a default - build error that oncedid not occur (new gcc?) er C++ 3 08-25-2008 07:13 AM
Template construction in old gcc 3.3.3 does not compile in gcc 3.4.4 eknecronzontas@yahoo.com C++ 5 09-17-2005 12:27 AM
parse error in gcc but success in vc.net, call a non_template class's template member function from a template class's member function! ken C++ 2 06-28-2005 06:57 AM
Template Friend Function, GCC and C++ FAQ Lite Christophe Barbe C++ 2 10-20-2003 10:33 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57