LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 05-14-2005, 01:55 PM   #1
enemorales
Member
 
Registered: Jul 2004
Location: Santiago, Chile
Distribution: Ubuntu
Posts: 410

Rep: Reputation: 30
C++ Templated Class and Borland C++ Compiler


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;  
}
 
Old 09-25-2010, 02:26 PM   #2
Greatwolf
LQ Newbie
 
Registered: Nov 2008
Posts: 6

Rep: Reputation: 0
Thumbs down

you're getting that error because you're including the wrong header files.

Do this instead:

Code:
#include <iostream>
// or if you just want output stream
// #include <ostream>

using namespace std;
And why are you posting this question here? It has absolutely nothing to do with linux
 
Old 09-25-2010, 02:30 PM   #3
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
Quote:
Originally Posted by Greatwolf View Post
And why are you posting this question here? It has absolutely nothing to do with linux
It's in the programming forum, so it's fine:

This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Implementing a vector class from a list class purefan Programming 9 04-14-2005 10:48 PM
PHP: how to use a method from a class in the same class ldp Programming 5 09-17-2004 09:52 AM
BlackBox.class & VerifierBug.class virus ??? dalek Linux - Security 4 02-29-2004 08:55 AM
Inheriting class members (Qt C++, QApplication class) jtshaw Programming 2 01-15-2004 11:52 AM
c++ : regarding (inheritence)base class and derived class edreddy Programming 6 07-31-2002 06:33 PM


All times are GMT -5. The time now is 08:23 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration