Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Template

Template

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++debugging
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Alex_Y
    wrote on last edited by
    #1

    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. :)

    M 1 Reply Last reply
    0
    • A Alex_Y

      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. :)

      M Offline
      M Offline
      Michael Dunn
      wrote on last edited by
      #2

      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.

      A 1 Reply Last reply
      0
      • M Michael Dunn

        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.

        A Offline
        A Offline
        Alex_Y
        wrote on last edited by
        #3

        Thanks man. I aways thought that in VS6 I was able to sepparate it. My bad. :)

        J 1 Reply Last reply
        0
        • A Alex_Y

          Thanks man. I aways thought that in VS6 I was able to sepparate it. My bad. :)

          J Offline
          J Offline
          Jack Puppy
          wrote on last edited by
          #4

          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

          T 1 Reply Last reply
          0
          • J Jack Puppy

            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

            T Offline
            T Offline
            Tim Smith
            wrote on last edited by
            #5

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

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups