Saturday, February 19, 2011

How do I resolve: "error C2039: '{ctor}' : is not a member of" in Visual Studio 2005?

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

From stackoverflow
  • 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:

    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

  • 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>
    
  • 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 :)

    SDX2000 : 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.

0 comments:

Post a Comment