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 get the
following error:
Error: Unresolved external 'operator <<(std::basic_o stream<char,
std::char_trait s<char> >&, const BinomialTree<in t>&)' referenced from
C:\DOCUMENTS AND SETTINGS\RYAN\D ESKTOP\COMPUTER SCIENCE\CS
2413\PROJECTS\P ROJECT 3\PROJ3.OBJ
I'm almost certain that this is somehow caused by the templates, because
when I remove all 'templating' from the classes, everything works
perfectly. Here is the relevant code:
template<class Object>
class BinomialTree
{
friend ostream& operator<< <>(ostream& stream, const
BinomialTree<Ob ject>& tree);
private:
//array of Binomial Node pointers
BinomialNode<Ob ject>* locations[100];
...stuff here
};
template<class Object>
ostream& operator<< (ostream& stream, const BinomialTree<Ob ject>& tree)
{
for(int j = 0; j<100; j++)
{
if(tree.locatio ns[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<Ob ject>& node);
private:
void copy(const BinomialNode<Ob ject>& rhs);
Object _key; //the key for this class, ideally an integer value
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 here
};
template<class Object>
ostream& operator<< <>(ostream& stream, const
BinomialNode<Ob ject>& node)
{
stream<<node._k ey;
if(node.down != NULL)
return stream<<(*(node .down));
else {
if(node.next == NULL)
return stream;
else
return stream<<(*(node .next));
}
}
void main()
{
BinomialTree<in t> myTree;
cout<<myTree;
}
Any help would be greatly appreciated. Thanks.
--
Posted via
http://dbforums.com