template problem with ostream operator (Borland compiler)

R

Ryan M. Keith

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));
}
}
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top