friend template error in gcc 4.1

Discussion in 'C++' started by abelahcene@gmail.com, May 22, 2007.

  1. Guest

    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;
    }
     
    , May 22, 2007
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Christophe Barbe
    Replies:
    2
    Views:
    1,216
    Christophe Barbe
    Oct 20, 2003
  2. Replies:
    5
    Views:
    370
    Nathan Addy
    Sep 17, 2005
  3. Replies:
    12
    Views:
    1,145
  4. A L
    Replies:
    1
    Views:
    516
    Alf P. Steinbach /Usenet
    Aug 25, 2010
  5. Peter
    Replies:
    2
    Views:
    287
    Öö Tiib
    Jun 6, 2013
Loading...

Share This Page