Pure functions still pure after definition

T

Todd Aspeotis

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
 
R

Rolf Magnus

Todd said:
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?
 
U

Uenal Mutlu

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.
 
K

Kanenas

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,733
Messages
2,569,439
Members
44,829
Latest member
PIXThurman

Latest Threads

Top