In article <ge7gb.18613$pv6.10579@twister.nyc.rr.com>, "Rupert
harrison" <Wu
Tang@nyc.rr.com> says...
[ ... ]
[color=blue]
> #ifndef BSTree_H
> #define BSTree_H[/color]
This is normally used in headers, a point that will become important
below.
[color=blue]
> template<class DT>
> class BSTree[/color]
This means that from here to the end of the template declaration, "DT"
will refer to whatever type is used to instantiate the template.
[color=blue]
> template <class DT>
> class TNode
> {
> TNode *right;
> TNode *left;
>
> public:
> DT *info;
>
> friend class BSTree;
> };[/color]
At least if I understand what you're doing, making this into a separate
template isn't needed. It would be necessary if and only if you wanted
to support instantiating a TNode over a different type than its
surrounding BSTree was being instantiated over. From the looks of
things, that's not the case though -- a BSTree<X> implies TNode<x> as
well. In that case, you can simplify TNode a bit:
class TNode {
TNode *left, *right;
public:
DT *info;
friend class BSTree;
};
[color=blue]
> };[/color]
This is the end of the template declaration -- at this point, "DT"
ceases to mean anything (unless something else has declared it has
having a meaning. Given that this is a header, you (normally) don't
want to assume that it means anything beyond this point (i.e. a header
normally shouldn't assume anything about the "environment" into which
it's included.
[color=blue]
> static BSTree <DT> words;[/color]
That means at this point, "BSTree<DT>" is meaningless -- if you want to
instantiate BSTree, you have to supply _some_ real type.
Another point about headers, however, is that they should normally
declare types, but NOT define objects. I consider it highly doubtful
that this should be here at all. Perhaps you can tell us what this is
intended to accomplish, and we can help you toward accomplishing it.
--
Later,
Jerry.
The universe is a figment of its own imagination.