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

  • Home
  • SEARCH
  • 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 7828385
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T10:20:14+00:00 2026-06-02T10:20:14+00:00

Can I use variadic templates without using the template parameters as function parameters? When

  • 0

Can I use variadic templates without using the template parameters as function parameters?

When I use them, it compiles:

#include <iostream>
using namespace std;

template<class First>
void print(First first)
{
    cout << 1 << endl;
}

template<class First, class ... Rest>
void print(First first, Rest ...rest)
{
    cout << 1 << endl;
    print<Rest...>(rest...);
}

int main()
{
    print<int,int,int>(1,2,3);
}

But when I don’t use them, it doesn’t compile and complains about an ambiguity:

#include <iostream>
using namespace std;

template<class First>
void print()
{
    cout << 1 << endl;
}

template<class First, class ... Rest>
void print()
{
    cout << 1 << endl;
    print<Rest...>();
}

int main()
{
    print<int,int,int>();
}

Unfortunately the classes I want to give as template parameters are not instantiable (they have static functions that are called inside of the template function).
Is there a way to do this?

  • 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-02T10:20:14+00:00Added an answer on June 2, 2026 at 10:20 am
    template<class First> // 1 template parameter
    void print()
    {
        cout << 1 << endl;
    }
    
    #if 0
    template<class First, class ... Rest> // >=1 template parameters -- ambiguity!
    void print()
    {
        cout << 1 << endl;
        print<Rest...>();
    }
    #endif
    
    template<class First, class Second, class ... Rest> // >=2 template parameters
    void print()
    {
        cout << 1 << endl;
        print<Second, Rest...>();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class factory where I'm using variadic templates for the c'tor parameters
Possible Duplicate: trailing return type using decltype with a variadic template function I want
In Java, we can use variadic function in the following way: public Set packStrings(String...strings){
I can use the MS Word ActiveX control in order to access some parameters
I would like to use C++11's variadic templates to achieve a generalized random picker
I don't know if this can be achieved through variadic template, variadic marcos or
can i use hibernate to login jsp page using (session) if i'm not using
How can use the WebBrowser control in WPF to navigate using Search engine uri
I can use GTK allocation function, but that only gives the position relative to
A hypothetical variadic template tuple class would, as far as I can tell, have

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.