Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8928219
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:23:14+00:00 2026-06-15T08:23:14+00:00

I have a template class, let’s call it foo. In the implementation, I have:

  • 0

I have a template class, let’s call it foo. In the implementation, I have:

template<class a, class b ... class x>
void foo<a, b, ..., x>::function1() { }

template<class a, class b ... class x>
void foo<a, b, ..., x>::function2() { }

Now I want to make it simpler to read. Could I do something like typedef to
define a THING that is

template<class a, class b... class x> foo<a, b, ..., x>

then make the above function header simpler (shorter)?

THanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T08:23:15+00:00Added an answer on June 15, 2026 at 8:23 am

    The first question is, does your class template really need that many parameters? If so, can they be packed up in some way?

    Second, if the boilerplate of defining all of the functions out-of-line is overwhelming the actual code, why not define them inline, in the class definition? Yes, some people consider that generally bad style, but it’s a tradeoff—the goal of that guideline is to make your code more readable, and if it’s having the opposite effect, ignore it.

    Even if you want to keep the implementation in a separate .ipp file that gets included at the end of the .hpp file for better code organization, you can change that to including the .ipp in the middle:

    foo.hpp:

    template <class a, class b ... class x>
    class foo {
      #include "foo_impl.ipp"
    };
    

    foo_impl.ipp:

    void function1() {}
    void function2() {}
    

    If neither of those ideas appeals to you, there’s no way a typedef or template alias could help, because that’s for giving names to specializations of templates. No matter what you do, any template parameters that are still free, still have to be listed, or the compiler won’t know what you’re talking about.

    But you could always use the preprocessor:

    #define FOOMETHOD(rettype) template<class a, class b ... class x> \
                               rettype foo<a, b, ..., x>
    
    FOOMETHOD(void)::function1() { }
    FOOMETHOD(void)::function2() { }
    

    There are lots of ways you could modify this—put the :: in the macro, break it into two macros so you don’t need to pass in the rettype, define a different macro for each type, etc. Whatever looks most reasonable for your use case, do that.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's assume we have a template function foo: template<class T> void foo(T arg) {
I have a class template, let's call it A , which has a member
Let's say I have a template: template <class N, class I> void add(N* element,
Let's say i have following class: template <typename T> class CModule{ public: virtual void
very quick question, let's say I have a template: template <class T> class foo
I want to have a template class that looks something like what I have
Let's say you have a c++0x std::array member of a template class and you
Let's say we have a class, MyParent: class MyParent { public: template<namespace T> MyParent()
Let's say we have a template class Area , which has a member variable
Let's assume that I have following class template: <> - read as template template<template<class

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.