inline virtual destructor in a header file??

Joined
Mar 12, 2009
Messages
1
Reaction score
0
Problem With Inlining

Guys,

I have an issue with Inline Functions, consider the following header file for stack.

////////////////////////////////////////////////////////////////////////////////////
// Stack.h
#ifndef __STACK_H_INCLUDED__
#define __STACK_H_INCLUDED__

namespace Engine
{
template <class _Type>
class CStack
{
public:
__forceinline CStack(void);
virtual ~CStack(void);
private:
// Data Needed for Stack
};
}

// This is where i can put the Destructor Body which works
//template <class _Type>
//Engine::CStack<_Type>::~CStack( void )
//{
//}

#include "Stack.inl"

#endif // __STACK_H_INCLUDED__

///////////////////////////////////////////////////////////////////////////////
// Stack.inl

namespace Engine
{
template <class _Type>
__forceinline CStack<_Type>::CStack(void)
{
// Allocate Memory
}
}
///////////////////////////////////////////////////////////////////////////////
// Stack.cpp

#include "Stack.h"

namespace Engine
{
//-----------------------------------------------------------------------//
template <class _Type>
CStack<_Type>::~CStack(void)
{
// do the deletion here
}
//-----------------------------------------------------------------------//
}

////////////////////////////////////////////////////////////////////////////////////
Now the Problem,
If i define the Destructor in the header file after the Class Difinition, i get a successfull compile,

But if the Body of the Destructor is in the Stack.cpp file i get a Linker Error LNK2019.

Now if i remove the Virtual Qualifier from the ~CStack(void),,, and define the function any where in header or inline or cpp, i get a successfull compile again,,

what is going on? i can't understand all this .

Please Note the Namespace "Engine" Used and also the __forcinline instead of inline, but they essentially bahave the same in my case.


any kind of help would be greatly appriciate.

..
waZim
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top