Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > template problem with ostream operator (Borland compiler)

Reply
Thread Tools

template problem with ostream operator (Borland compiler)

 
 
Ryan M. Keith
Guest
Posts: n/a
 
      10-16-2003
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));
}
}
 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Strange compiler error w.r.t 'friend ostream& operator<< <>(ostream&,...)' abhay.burli@gmail.com C++ 2 02-26-2009 06:18 AM
template problem with ostream operator keit6736 C++ 2 10-17-2003 01:03 AM
template problem with ostream operator (Borland compiler) Ryan M. Keith C++ 0 10-16-2003 12:39 AM
ABC ostream & operator << Victor Irzak C++ 3 09-21-2003 04:29 AM
ostream operator joesoap C++ 1 08-20-2003 02:17 PM



Advertisments