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. Need help in template

Need help in template

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++
4 Posts 2 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.
  • S Offline
    S Offline
    Subrat 4708266
    wrote on last edited by
    #1

    Hi I am facing problem in accessing the function template written inside a class. My code is as follows. Please help me in this regard. mytemp.h class mytemp { public: mytemp(void); ~mytemp(void); template static T templateadd(T x, T y); }; mytemp.cpp template T mytemp::templateadd(T x, T y) { return (x + y); } main.cpp int _tmain(int argc, _TCHAR* argv[]) { cout<<mytemp::templateadd(10,2); // Here I am getting error: unresolved external symbol ... //Here I want to access templatedadd() of mytemp class. Please tell me What should be the statement. return 0; }

    S 1 Reply Last reply
    0
    • S Subrat 4708266

      Hi I am facing problem in accessing the function template written inside a class. My code is as follows. Please help me in this regard. mytemp.h class mytemp { public: mytemp(void); ~mytemp(void); template static T templateadd(T x, T y); }; mytemp.cpp template T mytemp::templateadd(T x, T y) { return (x + y); } main.cpp int _tmain(int argc, _TCHAR* argv[]) { cout<<mytemp::templateadd(10,2); // Here I am getting error: unresolved external symbol ... //Here I want to access templatedadd() of mytemp class. Please tell me What should be the statement. return 0; }

      S Offline
      S Offline
      sashoalm
      wrote on last edited by
      #2

      This is a subtle problem with templates, there's an explanation ahy it happens in here[^]

      There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition. Blaise Pascal

      S 1 Reply Last reply
      0
      • S sashoalm

        This is a subtle problem with templates, there's an explanation ahy it happens in here[^]

        There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition. Blaise Pascal

        S Offline
        S Offline
        Subrat 4708266
        wrote on last edited by
        #3

        Really helpfull. Thanks a lot Sashoalm.

        S 1 Reply Last reply
        0
        • S Subrat 4708266

          Really helpfull. Thanks a lot Sashoalm.

          S Offline
          S Offline
          sashoalm
          wrote on last edited by
          #4

          No problem :)

          There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition. Blaise Pascal

          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