Template
-
I have simple class template< class TProblemType > class CFemInput { public: CFemInput(CFemInputAdapter::eAdapterType eType, const TCHAR* szFileName); virtual ~CFemInput(void); private: // proxy class CFemInputAdapter* m_pAdapter; }; template< class TProblemType > CFemInput< TProblemType >::CFemInput(CFemInputAdapter::eAdapterType eType, const TCHAR* szFileName) : m_pAdapter(NULL) { switch(eType) { default: case eFile: m_pAdapter = new TProblemType(szFileName); break; } } template< class TProblemType > CFemInput< TProblemType >::~CFemInput(void) { } For some unknown reasons I getting link error if I split this code in h and cpp file. If everything in one h file everything is fine. Why linker can't find constructor or destructor if they in sepparate files. First time have such problem. I have VS2003 under debug (no optimisations) Thanks. :)
-
I have simple class template< class TProblemType > class CFemInput { public: CFemInput(CFemInputAdapter::eAdapterType eType, const TCHAR* szFileName); virtual ~CFemInput(void); private: // proxy class CFemInputAdapter* m_pAdapter; }; template< class TProblemType > CFemInput< TProblemType >::CFemInput(CFemInputAdapter::eAdapterType eType, const TCHAR* szFileName) : m_pAdapter(NULL) { switch(eType) { default: case eFile: m_pAdapter = new TProblemType(szFileName); break; } } template< class TProblemType > CFemInput< TProblemType >::~CFemInput(void) { } For some unknown reasons I getting link error if I split this code in h and cpp file. If everything in one h file everything is fine. Why linker can't find constructor or destructor if they in sepparate files. First time have such problem. I have VS2003 under debug (no optimisations) Thanks. :)
See the C++ FAQ Lite: [35.7] Why can't I separate the definition of my templates class from it's declaration and put it inside a .cpp file?[^] --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | 1ClickPicGrabber | CP SearchBar v2.0.2 | C++ Forum FAQ Laugh it up, fuzzball.
-
See the C++ FAQ Lite: [35.7] Why can't I separate the definition of my templates class from it's declaration and put it inside a .cpp file?[^] --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | 1ClickPicGrabber | CP SearchBar v2.0.2 | C++ Forum FAQ Laugh it up, fuzzball.
-
I have sometimes separated them using an .inl file.
:suss: Pssst. You see that little light on your monitor? That's actually a government installed spy camera. Smile and wave to big brother!
Painted on the side of a dog trainer's van: SIT HAPPENS -
I have sometimes separated them using an .inl file.
:suss: Pssst. You see that little light on your monitor? That's actually a government installed spy camera. Smile and wave to big brother!
Painted on the side of a dog trainer's van: SIT HAPPENSBut the INL file still is compiled into each of the CPP files needing the template function definitions. Saying that the functions must be implemented in the H file is just the easy and quick answer to a more complicated issue. To be more correct, a template function/method implementation must be in the same compliation module as where it is referenced. (I don't know exactly what the standard says.) Tim Smith I'm going to patent thought. I have yet to see any prior art.