views:

1435

answers:

4

I am extending a template class using C++ in Visual Studio 2005. It is giving me an error when I try to extend the template base class with:

template <class K, class D>
class RedBlackTreeOGL : public RedBlackTree<K, D>::RedBlackTree  // Error 1
{
 public:
  RedBlackTreeOGL();
  ~RedBlackTreeOGL();

and a second error when I try to instantiate the object:

RedBlackTreeOGL<double, std::string> *tree = new RedBlackTreeOGL<double, std::string>; // error 2

Error 1:

**redblacktreeopengl.hpp(27) : error C2039: '{ctor}' : is not a member of 'RedBlackTree' with [ K=double, D=std::string ] **

Error 2:

main.cpp(50) : see reference to class template instantiation 'RedBlackTreeOGL' being compiled

+1  A: 

Does RedBlackTree<K, D>::RedBlackTree have a default constructor? C++ doesnt define a default constructor by itself if you have other parameterized constructors (ctors).

SDX2000
A: 

@SDX2000:

Yes, I have defined a constructor in RedBlackTree::RedBlackTree:

template <class K, class D>
class RedBlackTree
    {
    public:
        RedBlackTree();
        // Deleting a storage object clears all remaining nodes
        ~RedBlackTree();

I have also implemented a body for the constuctor and destructor for RedBlackTree class

Brock Woolf
+4  A: 

The code is trying to inherit a constructor, not a class :-)

The start of the class declaration should be

template <class K, class D>
class RedBlackTreeOGL : public RedBlackTree<K, D>
James Hopkin
+2  A: 

OMG, I feel so silly..... been looking at my own code for far too long!

Thats a pretty basic thing and I dont know how i missed it!

Thank you James (and SDX2000) this worked by taking the "constructor" off the end of the declaration to what James said.

Thank you :)

Brock Woolf
Hey stuff happens! I thought RedBlackTree was an inner class but missed the fact that the outer class had the same name as the inner class which is not possible hence the second RedBlackTree was the ctor.
SDX2000