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

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

    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,336
    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をこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    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
    2,665
    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,336
    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.

  6. #6
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    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
    “Salem Was Wrong!” -- Pedant Necromancer
    “Four isn't random!” -- Gibbering Mouther

  7. #7
    Registered User MutantJohn's Avatar
    Join Date
    Feb 2013
    Posts
    2,665
    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,336
    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, 09:15 AM
  3. Template functions
    By starcatcher in forum C++ Programming
    Replies: 6
    Last Post: 02-07-2008, 06: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