Templates

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • d0ugg
    New Member
    • Jan 2007
    • 41

    Templates

    Hi,

    I need to create a program that works with class templates and regular function templates.
    Can I create one single program that works with both in the same code?

    Sorry for the question but all programs that I was looking just works with one or the other.

    Thanks,

    doug
  • Studlyami
    Recognized Expert Contributor
    • Sep 2007
    • 464

    #2
    yeah you can. Most examples try to break things down to one at a time.

    Comment

    • d0ugg
      New Member
      • Jan 2007
      • 41

      #3
      Do you know where can I find a simple example?
      Thanks

      Doug

      Comment

      • Studlyami
        Recognized Expert Contributor
        • Sep 2007
        • 464

        #4
        http://www.cplusplus.c om/doc/tutorial/templates.html

        Has function templates, then class templates which contains a function of the class.

        Comment

        • d0ugg
          New Member
          • Jan 2007
          • 41

          #5
          Alright, I think that I understood.

          Thanks,

          Doug

          Comment

          • d0ugg
            New Member
            • Jan 2007
            • 41

            #6
            So one more question..
            The member-function definitions of a class template are function templates?

            thanks,

            doug

            Comment

            • weaknessforcats
              Recognized Expert Expert
              • Mar 2007
              • 9214

              #7
              Originally posted by D0ugg
              So one more question..
              The member-function definitions of a class template are function templates?
              Yes. Because you need the template type to write the member function:
              [code=cpp]
              template <class T>
              class MyClass
              {
              public:
              void AMethod();
              };
              template <class T>
              void MyClass<T>::AMe thod()
              {

              }
              [/code]

              Comment

              • d0ugg
                New Member
                • Jan 2007
                • 41

                #8
                Oh, okay.

                Thank you very much,

                ~doug

                Comment

                Working...