473,320 Members | 2,012 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,320 software developers and data experts.

template problem with ostream operator (Borland compiler)

I am having a problem with the ostream operator in templated classes
that I wrote (I'm using the Borland compiler), and I'm certain that
the templates are the problem because when I remove the templating
completely everything works perfectly. Here is the error message:
Error: Unresolved external 'operator <<(std::basic_ostream<char,
std::char_traits<char> >&, const BinomialTree<int>&)' referenced from
C:\DOCUMENTS AND SETTINGS\RYAN\DESKTOP\COMPUTER SCIENCE\CS
2413\PROJECTS\PROJECT 3\TEMP\TMPPROJ3.OBJ

And here is the relevant code:

template<class Object>
class BinomialTree
{
friend ostream& operator<< (ostream& stream, const
BinomialTree<Object>& tree);

private:
//array of Binomial Node pointers
BinomialNode<Object>* locations[100];

....more stuff
};

template<class Object>
ostream& operator<< (ostream& stream, const BinomialTree<Object>&
tree)
{
for(int j = 0; j<100; j++)
{
if(tree.locations[j] != NULL)
{
stream<<(*(tree.locations[j]));
}
}
return stream;
}

template <class Object>
class BinomialNode
{
//overloaded ostream operator, for displaying
friend ostream& operator<< (ostream& stream, const
BinomialNode<Object>& node);

private:
void copy(const BinomialNode<Object>& rhs);
Object _key;
int _degree;

BinomialNode* next; //pointer to the next node (a sibling)
BinomialNode* down; //the pointer to the child
BinomialNode* up; //the pointer to this node's parent

....more stuff
};

template<class Object>
ostream& operator<< (ostream& stream, const BinomialNode<Object>&
node)
{
stream<<node._key;

if(node.down != NULL)
return stream<<(*(node.down));

else {

if(node.next == NULL)
return stream;
else
return stream<<(*(node.next));
}
}
Jul 19 '05 #1
0 2041

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

Similar topics

2
by: keit6736 | last post by:
Hi, I'm using the Borland compiler and I've created two templated classes in which I've overloaded the ostream << operator. However, when I try and use the operator on objects of either class I...
2
by: Christophe Barbe | last post by:
I posted a few days ago about the same problem but was not very clear. So here is my second take at it. Basically with GCC 3.3.2, I can't compile the example from the C++ FAQ Lite available...
6
by: Adam Parkin | last post by:
Hello, all I'm having a problem with friend functions in a templatized Queue class I'm writing using linked lists. The problem is that I can't get the friend function to be able to access private...
1
by: paidojoao-groups | last post by:
Given this code: #include <iostream> #include <string> class timestamp { public: timestamp() {
5
by: James Aguilar | last post by:
Hello, all. I saw this in the provided code of a lab that I have due in a couple of weeks in my algorithms class. It compiled fine in g++ but did not compile with the VC++ compiler. It does...
7
by: Jim Langston | last post by:
What I want to do is have an operator= accept a template variable. I will have some classes which all will contain an instance of a different class. I want an operator= in yet a 3rd class to...
3
by: Hamilton Woods | last post by:
Diehards, I developed a template matrix class back around 1992 using Borland C++ 4.5 (ancestor of C++ Builder) and haven't touched it until a few days ago. I pulled it from the freezer and...
0
by: abelahcene | last post by:
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 <) ...
2
by: syang8 | last post by:
Dear all, I am trying to design classes with stream support. Basically, I want the operator << work for the base class and all the derived classes. If the base class is a template class, and...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.