Like Tree2Likes
  • 2 Post By tabstop

How do I get a set of functions to all use the same template?

This is a discussion on How do I get a set of functions to all use the same template? within the C++ Programming forums, part of the General Programming Boards category; I'm getting tired of writing Code: template <typename T> everywhere. Is the only solution to encapsulate all my desired functions ...

  1. #1
    Registered User MutantJohn's Avatar
    Join Date
    Feb 2013
    Posts
    1,082

    How do I get a set of functions to all use the same template?

    I'm getting tired of writing
    Code:
    template <typename T>
    everywhere.

    Is the only solution to encapsulate all my desired functions in a templated class?

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by MutantJohn View Post
    I'm getting tired of writing
    Code:
    template <typename T>
    everywhere.

    Is the only solution to encapsulate all my desired functions in a templated class?
    If you do that, then you'll have to do more typing, since each function will now start with
    Code:
    template <typename T>
    classname<T>::
    Make a macro.

  3. #3
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,614
    Quote Originally Posted by tabstop View Post
    If you do that, then you'll have to do more typing, since each function will now start with
    Code:
    template <typename T>
    classname<T>::
    No, not if you do like many others do and write the class inline.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #4
    Registered User MutantJohn's Avatar
    Join Date
    Feb 2013
    Posts
    1,082
    Lol what does make a macro mean? Do I just define T as a type in a .hpp file or something?

  5. #5
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by MutantJohn View Post
    Lol what does make a macro mean? Do I just define T as a type in a .hpp file or something?
    You set up your text editor so that when you type some weird keystroke (like, I don't know, F6, or Ctrl-T) it turns that keystroke into your line you don't want to type.
    phantomotap and Elysia like this.

  6. #6
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    4,261
    O_o

    I think we all thought you intended preprocessor macro; I can get behind the suggestion of using tools provided by text editors.

    Soma
    “Often out of periods of losing come the greatest strivings toward a new winning streak.” -- Fred Rogers
    “Salem Was Wrong!” -- Pedant Necromancer

  7. #7
    Registered User MutantJohn's Avatar
    Join Date
    Feb 2013
    Posts
    1,082
    Quote Originally Posted by tabstop View Post
    You set up your text editor so that when you type some weird keystroke (like, I don't know, F6, or Ctrl-T) it turns that keystroke into your line you don't want to type.
    Omg, why didn't I think to do this!?!?

  8. #8
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by phantomotap View Post
    O_o

    I think we all thought you intended preprocessor macro; I can get behind the suggestion of using tools provided by text editors.

    Soma
    The idea of the preprocessor macro didn't even enter my head, or else I would definitely have been more specific.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Implementation of template functions in .cpp?
    By cyberfish in forum C++ Programming
    Replies: 3
    Last Post: 10-20-2010, 11:29 AM
  2. template functions?
    By ovid in forum C++ Programming
    Replies: 8
    Last Post: 02-25-2010, 08:15 AM
  3. Template functions
    By starcatcher in forum C++ Programming
    Replies: 6
    Last Post: 02-07-2008, 05:21 AM
  4. using Template Functions
    By ashcan1979 in forum C++ Programming
    Replies: 3
    Last Post: 09-20-2006, 12:44 AM
  5. Template functions
    By ygfperson in forum C++ Programming
    Replies: 4
    Last Post: 06-24-2003, 02:56 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21