By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,079 Members | 843 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,079 IT Pros & Developers. It's quick & easy.

template problem with ostream operator (Borland compiler)

P: n/a
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
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.