473,405 Members | 2,310 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

friend template error in gcc 4.1

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>::operator [] (int i){
return ptrVect [i];
}
template <class T>
Vector<T Vector<T>::operator + ( Vector <T& tab){
Vector<Tv(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 <intv1(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 '07 #1
0 1136

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Dmitry D | last post by:
Hi all, I'm having problems with declaring a template friend function. It seems like I've done everything as explained in C++ FAQ, but still, I'm getting the linker error (unresolved external...
5
by: Yoon-Soo Lee | last post by:
I am using Visual C++ .NET 2003 and running into some linking error from the following template code. The error messages is error LNK2019: unresolved external symbol "class...
5
by: Trevor Lango | last post by:
What is the appropriate syntax for placing a friend function that includes as one of it's parameters a pointer to the class object itself within the template class? I have the following: ...
6
by: Ben Ingram | last post by:
Hi all, I am writing a template matrix class in which the template parameters are the number of rows and number of columns. There are a number of reasons why this is an appropriate tradeoff for...
3
by: 胡岳偉(Yueh-Wei Hu) | last post by:
Hi all, I have 2 questions about template function as friends in template classes. I don't know why, and hope someone could help me. ...
0
by: Yueh-Wei Hu | last post by:
Victor Bazarov <v.Abazarov@comAcast.net> wrote in message news: ============================================================== > > Question 1: > >...
2
by: Ruben Campos | last post by:
I have a problem with a template function that is declared as a friend of a template class. I'll first show the exact problem with source code: // MyClass.hpp template <typename T> class...
4
by: fdmfdmfdm | last post by:
I have the following code: #include <iostream> #include <cstdlib> #include <cassert> using namespace std; template <class T> class Stack{ public: enum{DefaultStack = 10, EmptyStack = -1};
3
by: jdurancomas | last post by:
Dear all, I'm trying to declare the operator++ to a nested class. The nested class is not template but the container it is. The code used in teh sample program is included bellow: ...
9
by: wo3kie | last post by:
#include <iostream> #include <map> #include <utility> // // Base // / | \ // Derived1 Derived2 \ // \ | / // Derived3
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.