Pure functions still pure after definition

Discussion in 'C++' started by Todd Aspeotis, Apr 27, 2005.

  1. Hello all. I've been having some very weird compiler errors in regards
    to my classes. I have my base node class here:

    template <class T> class CNode : public CManaged
    //-- Base node used to traverse either dynamic or static data
    structures
    //-- transparently.
    {
    public:
    //-- Declarations:
    typedef T baseType;
    //-- Data:
    T m_tData;
    //-- Default constructor/destructor:
    CNode();
    ~CNode();
    //-- Transparent traversal:
    inline virtual CNode<T> *getLeft() = 0;
    inline virtual CNode<T> *getRight() = 0;

    AUTO_SIZE;
    };

    And then later on down the track I have my dynamically overloaded
    node:

    template <class T> class CNode_Dynamic : public CNode<T>
    //-- Node used to traverse a dynamic data structure. Derived from
    CNode<T>.
    {
    public:
    //-- Data:
    CNode_Dynamic *m_pnLeft;
    CNode_Dynamic *m_pnRight;
    //-- Default constructor/destructor:
    CNode_Dynamic();
    ~CNode_Dynamic();
    //-- Transparent traversal:
    inline CNode<T> *getLeft();
    inline CNode<T> *getRight();

    AUTO_SIZE;
    };

    Finally, I have the implementation of getLeft() and getRight() here:

    template <class T> CNode<T> *CNode_Dynamic<T>::getLeft()
    {
    return m_pnLeft;
    }

    template <class T> CNode<T> *CNode_Dynamic<T>::getRight()
    {
    return m_pnRight;
    }

    Now, what VC++ . NET is telling me that it can't initiate an abstract
    class of CNode_Dynamic<int> because I haven't defined getLeft or
    getRight. Is there something I'm missing? Any help would be much
    appreciated.

    -- Todd
     
    Todd Aspeotis, Apr 27, 2005
    #1
    1. Advertising

  2. Todd Aspeotis

    Rolf Magnus Guest

    Todd Aspeotis wrote:

    > Hello all. I've been having some very weird compiler errors in regards
    > to my classes. I have my base node class here:
    >
    > template <class T> class CNode : public CManaged
    > //-- Base node used to traverse either dynamic or static data
    > structures
    > //-- transparently.
    > {
    > public:
    > //-- Declarations:
    > typedef T baseType;
    > //-- Data:
    > T m_tData;
    > //-- Default constructor/destructor:
    > CNode();
    > ~CNode();
    > //-- Transparent traversal:
    > inline virtual CNode<T> *getLeft() = 0;
    > inline virtual CNode<T> *getRight() = 0;
    >
    > AUTO_SIZE;
    > };
    >
    > And then later on down the track I have my dynamically overloaded
    > node:
    >
    > template <class T> class CNode_Dynamic : public CNode<T>
    > //-- Node used to traverse a dynamic data structure. Derived from
    > CNode<T>.
    > {
    > public:
    > //-- Data:
    > CNode_Dynamic *m_pnLeft;
    > CNode_Dynamic *m_pnRight;
    > //-- Default constructor/destructor:
    > CNode_Dynamic();
    > ~CNode_Dynamic();
    > //-- Transparent traversal:
    > inline CNode<T> *getLeft();
    > inline CNode<T> *getRight();
    >
    > AUTO_SIZE;
    > };
    >
    > Finally, I have the implementation of getLeft() and getRight() here:


    Where is "here"?

    > template <class T> CNode<T> *CNode_Dynamic<T>::getLeft()
    > {
    > return m_pnLeft;
    > }
    >
    > template <class T> CNode<T> *CNode_Dynamic<T>::getRight()
    > {
    > return m_pnRight;
    > }
    >
    > Now, what VC++ . NET is telling me that it can't initiate an abstract
    > class of CNode_Dynamic<int> because I haven't defined getLeft or
    > getRight.


    What is telling you that? The compiler or the linker? What's the exact
    message?

    > Is there something I'm missing? Any help would be much
    > appreciated.
     
    Rolf Magnus, Apr 27, 2005
    #2
    1. Advertising

  3. Todd Aspeotis

    Uenal Mutlu Guest

    "Todd Aspeotis" wrote
    > Hello all. I've been having some very weird compiler errors in regards
    > to my classes. I have my base node class here:
    >
    > template <class T> class CNode : public CManaged
    > //-- Base node used to traverse either dynamic or static data
    > structures
    > //-- transparently.
    > {
    > public:
    > //-- Declarations:
    > typedef T baseType;
    > //-- Data:
    > T m_tData;
    > //-- Default constructor/destructor:
    > CNode();
    > ~CNode();
    > //-- Transparent traversal:
    > inline virtual CNode<T> *getLeft() = 0;
    > inline virtual CNode<T> *getRight() = 0;
    >
    > AUTO_SIZE;
    > };
    >
    > And then later on down the track I have my dynamically overloaded
    > node:
    >
    > template <class T> class CNode_Dynamic : public CNode<T>
    > //-- Node used to traverse a dynamic data structure. Derived from
    > CNode<T>.
    > {
    > public:
    > //-- Data:
    > CNode_Dynamic *m_pnLeft;
    > CNode_Dynamic *m_pnRight;
    > //-- Default constructor/destructor:
    > CNode_Dynamic();
    > ~CNode_Dynamic();
    > //-- Transparent traversal:
    > inline CNode<T> *getLeft();
    > inline CNode<T> *getRight();
    >
    > AUTO_SIZE;
    > };
    >
    > Finally, I have the implementation of getLeft() and getRight() here:
    >
    > template <class T> CNode<T> *CNode_Dynamic<T>::getLeft()
    > {
    > return m_pnLeft;
    > }
    >
    > template <class T> CNode<T> *CNode_Dynamic<T>::getRight()
    > {
    > return m_pnRight;
    > }
    >
    > Now, what VC++ . NET is telling me that it can't initiate an abstract
    > class of CNode_Dynamic<int> because I haven't defined getLeft or
    > getRight. Is there something I'm missing? Any help would be much
    > appreciated.


    Several reasons:
    You are using Microsoft's stuff which is not standards conform.
    And, IMO Microsoft's .NET stuff needs another 5 years of fixing to become bugfree.
    My advise is: to avoid such errors you should go strictly with ISO/ANSI/POSIX etc. standards.
     
    Uenal Mutlu, Apr 27, 2005
    #3
  4. Todd Aspeotis

    Kanenas Guest

    On 27 Apr 2005 04:11:28 -0700, (Todd Aspeotis)
    wrote:

    >Hello all. I've been having some very weird compiler errors in regards
    >to my classes. I have my base node class here:
    >
    >template <class T> class CNode : public CManaged

    [...]
    > inline virtual CNode<T> *getLeft() = 0;
    > inline virtual CNode<T> *getRight() = 0;

    [...]
    >template <class T> class CNode_Dynamic : public CNode<T>
    >//-- Node used to traverse a dynamic data structure. Derived from
    >CNode<T>.
    >{
    >public:

    [...]
    > inline CNode<T> *getLeft();
    > inline CNode<T> *getRight();
    >
    > AUTO_SIZE;
    >};
    >
    >Finally, I have the implementation of getLeft() and getRight() here:
    >
    >template <class T> CNode<T> *CNode_Dynamic<T>::getLeft()
    >{
    > return m_pnLeft;
    >}
    >
    >template <class T> CNode<T> *CNode_Dynamic<T>::getRight()
    >{
    > return m_pnRight;
    >}
    >
    >Now, what VC++ . NET is telling me that it can't initiate an abstract
    >class of CNode_Dynamic<int> because I haven't defined getLeft or
    >getRight. Is there something I'm missing? Any help would be much
    >appreciated.
    >


    Does the error occur before or after the definitions of
    CNode_Dynamic<T>::getLeft() and CNode_Dynamic<T>::getRight()? What if
    you move the 'inline' specifier from the in-class declarations of
    getLeft and getRight to the definitions? I may be way off with the
    second question; I have no experience with MS's visual compilers but
    am suspicious with how function specifiers interact with overloading
    under VC++.

    After playing around with similar code under g++ 3.3.2 and getting no
    errors, I think it's a VC++ issue, not a language issue. See what
    people have to say over in comp.os.ms-windows.programmer.*

    Kanenas
     
    Kanenas, May 30, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. _ivan
    Replies:
    4
    Views:
    361
    Hafiz Abid Qadeer
    Sep 6, 2003
  2. Jianli Shen
    Replies:
    1
    Views:
    592
    Victor Bazarov
    Mar 13, 2005
  3. Gerard Brunick

    Adding functions to classes after definition

    Gerard Brunick, Jan 9, 2007, in forum: Python
    Replies:
    0
    Views:
    276
    Gerard Brunick
    Jan 9, 2007
  4. John Goche
    Replies:
    10
    Views:
    753
    Marcus Kwok
    Dec 8, 2006
  5. Replies:
    4
    Views:
    797
    Ben C
    Mar 29, 2008
Loading...

Share This Page