Sign in to follow this  

Problem with Inlining

This topic is 3201 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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 appriciated. .. waZim

Share this post


Link to post
Share on other sites
Template functions need to be visible where used*, like inline functions. Keep them in the header file, or in a separate file included by the header (again, like your inline function).


* Not entirely true - currently there are two ways of avoiding this. One is to use explicit instantiation and the other is to use a compiler that supports the "export" keyword. Neither are really practical for most template classes.

Share this post


Link to post
Share on other sites
Thanks for quick reply, atleast i have stoped wasting time on trying to put the code difinitions in CPP File, :)

i knew it works in header file or inline file but it looks a little ugly i thought there might be another way of putting it inside cpp..

Share this post


Link to post
Share on other sites

This topic is 3201 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this