Hi,
I'm trying to write some very simple templated classes in C++, but I get the next error when I use Borland Compiler 5.5.1 (It works fine with gcc). The problem is with the overcharge of operator <<.
Thank you a lot in advance...
Code:
g:\bc55\bin\bcc32 -P -Ig:\bc55\include -Lg:\bc55\lib test2.cpp
Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
test2.cpp:
Error E2428 test2.cpp 16: Templates must be classes or functions
Error E2141 test2.cpp 16: Declaration syntax error
*** 2 errors in Compile ***
> Terminated with exit code 1.
Code:
#include <conio.h>
template <class T> class Couple;
template <class T>
class Couple {
public:
Couple();
Couple(T ax, T ay) : x(ax), y(ay) {};
T x;
T y;
};
template <class T>
ostream & operator << ( ostream & o, Couple<T> p ) {
o << "(" << p.x << "," << p.y << ")";
return o;
}
int main() {
Couple<double> p1(1,2);
Couple<double> p2(1.123,4.53);
cout << p1 << endl;
cout << p2 << endl;
}