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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T13:47:42+00:00 2026-06-06T13:47:42+00:00

I want to do something like this: template<template<int d, class> class container, int dim

  • 0

I want to do something like this:

template<template<int d, class>
         class container,
         int dim = d, typename content_data_type>
class MyClass {
};

My Compiler tells me that this is not possible because “d” is not defined outside of:

template<int d, class> class container

Is there maybe another way of doing this ?

Thanks in advance for any help on this topic.

UPDATE:

@ Rook: i want to access the “dim” and “content_data_type” parameters later on in a specialization

e.g.

General class:

template<template<int d, class>
         class container>
class MyClass {
};

Spec. class:

template<>
class MyClass<vec> {
    vec c; // Error: vec needs template parameters
};

This gave me an error because i used my template class “vec” whitout template parameters, i expected the compiler to deduce the template parameters, e.g. when i use

MyClass<vec<3, float> >

then variable “c” should have the type

vec<3, float>

Because this didn’t work, I thought i can create two excplicit template paramters “dim” and “content_data_type” which i can access in the specialization class like this:

template<template<int d, class t>
     class container,
     int dim = d, typename content_data_type = t>
class MyClass<vec> {
    vec<dim, content_data_type> c;
};

… and sorry again for not being specific enough with the initial question 🙂

  • 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-06T13:47:45+00:00Added an answer on June 6, 2026 at 1:47 pm

    I don’t think what you’re doing makes sense, so the answer is “no”.

    The template parameter container is a class template, not a class. When MyClass is instantiated, its argument is the whole template, not just one instantiation of it. So it’s not possible to default the dimension of MyClass to “the dimension of container“, because container doesn’t have values for its own template parameters. Your class MyClass can create and use one or more instantiations of container with different values of d, but it isn’t given any one of them in particular, it’s given the template.

    By analogy, suppose you pass a pointer-to-function f as a parameter to a function g. You can’t then use “the arguments passed to f” in the definition of g. The function g can call f one or more times with different arguments, but it isn’t given any one call in particular, it’s given the function.

    From your update:

    e.g. when i use MyClass<vec<3, float> >

    You don’t use MyClass<vec<3, float> >, there’s no such thing. As I say, MyClass takes a template not a class. vec is a template, vec<3, float> is a class. It sounds like maybe you don’t need a template as a template parameter at all.

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

Sidebar

Related Questions

I want to have something like this below: template <class T> struct Container{ public:
I want to do something like this: template <typename T:public Vertex> addTri( T v1,
I want to do something like this: require 'erb' @var = 'test' template =
I want to do something like this: class Dictable: def dict(self): raise NotImplementedError class
I want to do something like this declare @a int=1 if (@a=1) with cte
I have a C++ application that can be simplified to something like this: class
I want to specialize a template for STL's vector template arguments. Something like this:
I would like to write this: template<typename T1, typename T2> class OK { T1
I want something like this: abcdab.search(/a/g) //return [0,4] Is it possible?
I want to run something like this: For a = 0 To 4 For

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.