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 6685077
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:00:54+00:00 2026-05-26T05:00:54+00:00

What is the correct syntax to use template parameters of a template class argument

  • 0

What is the correct syntax to use template parameters of a template class argument in another template class?

For example: How can I access X and Y of class Param in class Foo?

Program:

template < template < int, int > class X1>
struct Foo {
int foo() {
printf("ok%d %d\n", X1::X, X1::Y);
return 0;
}};

template < int X, int Y >
class Param {
int x,y;
public:
Param(){x=X; y=Y;}
void printParam(){
cout<<x<<" "<<y<<"\n";
}
};

int main() {
Param<10, 20> p;
p.printParam();
Foo< Param > tt;
tt.foo();
return 0;
}

As such for the above code, for the printf statement compiler complains:

In member function 'int Foo<X1>::foo()':
Line 4: error: 'template<int <anonymous>, int <anonymous> > class X1' used without template parameters
compilation terminated due to -Wfatal-errors.
  • 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-05-26T05:00:55+00:00Added an answer on May 26, 2026 at 5:00 am

    You can’t. The template template parameter means that you take a template name without supplied template arguments.

    Foo< Param > tt;
    

    Here you can see that no values are supplied for Param. You’d take a template template parameter so that Foo itself could instantiate Params with any arguments it likes.

    Example:

    template < template < int, int > class X1>
    struct Foo {
    
        X1<1, 2> member;
    
        X1<42, 100> foo();
    };
    
    template <int N, int P> struct A {};
    
    template <int X, int Y> struct B {};
    
    Foo<A> a_foo;  //has a member of type A<1, 2>, foo returns A<42, 100>
    Foo<B> b_foo; //has a member of type B<1, 2>, foo returns B<42, 100>
    

    But if you want your Foo to output those integers, it has to take real types, not templates. Secondly, the names of the template arguments (X and Y) are only meaningful where they are in scope. They are otherwise completely arbitrary identifiers. You can retrieve the values with simple metaprogramming:

    #include <cstdio>
    
    template <class T>
    struct GetArguments;
    
    //partial specialization to retrieve the int parameters of a T<int, int>
    template <template <int, int> class T, int A, int B>
    struct GetArguments<T<A, B> >
    {
       enum {a = A, b = B};
    };
    //this specialization also illustrates another use of template template parameters:
    //it is used to pick out types that are templates with two int arguments
    
    template <class X1>
    struct Foo {
      int foo() {
        printf("ok%d %d\n", GetArguments<X1>::a, GetArguments<X1>::b);
        return 0;
      }
    };
    
    template < int X, int Y >
    class Param {
    public:
       void print();
    };
    
    //this is to illustrate X and Y are not essential part of the Param template
    //in this method definition I have chosen to call them something else
    template <int First, int Second> 
    void Param<First, Second>::print()
    {
       printf("Param<%d, %d>\n", First, Second);
    }
    
    int main() {
    
        Foo< Param<10, 20> > tt;
        tt.foo();
        Param<10, 20> p;
        p.print();
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can you please help me with the correct syntax to use when you want
How can I correct the following so that I don't receive a syntax error
A constructor of a class can be a template function. At the point where
I'm trying to figure out the correct syntax to use the pipe operator |>
I need to create a multi-dimensional (nested) hashtable/dictionary so that I can use syntax
What is the correct syntax when we use multiple patterns ? test3()-> test4(<<1234567890>>). test4(A)->
Here is class foo: template <typename T> struct foo { foo() { t =
I have a problem with the correct syntax to use UNION and GROUP_CONCAT in
What is the correct syntax for this: IList<string> names = Tom,Scott,Bob.Split(',').ToList<string>().Reverse(); What am I
What is the correct syntax to create objects in javascript that will work across

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.