• Advertisement
Sign in to follow this  

templated class

This topic is 4258 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a templated class (named BSTree), and inside of that class i have: typedef BinTreeNode* BinTree; and i have a function that needs to return type BinTree. for the implementation of this function i have: template <typename T> BSTree<T>::BinTree BSTree<T>::root(void) const { } but i am getting errors, i know i am missing something here, but i am not sure what. Thanks in advance.

Share this post


Link to post
Share on other sites
Advertisement
warning C4346: 'BSTree<T>::BinTree' : dependent name is not a type

error C2143: syntax error : missing ';' before 'BSTree<T>::root'

error C2501: 'BSTree<T>::BinTree' : missing storage-class or type specifiers


template <typename T>
class BSTree
{
public:
struct BinTreeNode
{
BinTreeNode *left;
BinTreeNode *right;
T data;
int balancefactor; // Optional
};
typedef BinTreeNode* BinTree;

private:
unsigned count_;
ObjectAllocator *allocator_;

// Other private fields and methods

public:
BSTree(ObjectAllocator *allocator = 0);
virtual ~BSTree();
virtual void insert(const T& value) throw(BSTException);
virtual void remove(const T& value);
void clear(void);
bool find(const T& value, unsigned &compares) const;
bool empty(void) const;
unsigned int size(void) const;
int height(void) const;
BinTree root(void) const;
};

Share this post


Link to post
Share on other sites
Oh, this one again. :) (This is a reasonable General Programming question, although we do see it a lot... "beginners" usually don't need to do this kind of stuff)


template <typename T>
typename BSTree<T>::BinTree BSTree<T>::root(void) const
{
// etc.


I would also recommend to you not to specify empty parameter lists as (void), but instead just (). Also, you might consider returning references rather than pointers. But then - since you're apparently implementing a binary search tree, it's quite likely you should just use std::set or std::map :s

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement