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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T19:41:44+00:00 2026-06-17T19:41:44+00:00

Is the following permissible when using templates. template <typename PAR1 = X, typename PAR2

  • 0

Is the following permissible when using templates.

template <typename PAR1 = X,
          typename PAR2 = Y,
          typename PAR3 = Z>
class Base {
   //some stuff inside
};

template <typename PAR1
          typename PAR2 = Z>
class Derived : public Base <PAR1,Y,PAR2> {
   //some stuff here
};

what i want here is that Derived class should always have the PAR2 type as Y.

Can we fix the parameter value when others parameters after it as optional while inheriting ?

  • 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-17T19:41:45+00:00Added an answer on June 17, 2026 at 7:41 pm

    I guess you are confused by template default value and partial specialization. Because Base takes 3 parameters with default value, you could instantiate Base with from 0 to 3 parameters.

    Base<> b1;              #1, PAR1=X,   PAR2=Y,   PAR3=Z
    Base<int> b2;           #2  Par1=int, PAR2=Y,   PAR3=Z
    Base<int, int> b3;      #3  PAR1=int, PAR2=int, PAR3=Z
    Base<int, int, int> b4; #4  PAR1=int, PAR2=int, PAR3=int 
    

    In Derived class, you are inheriting from situation #4 which is of course valid.

    So you can inherit from any form of Base above.

    Base template parameter can be independent type(value) or passed from template <typename PAR1, typename PAR2 = Y>

    template <typename PAR1,
              typename PAR2 = Y>
    class Derived : public Base <> {
    };
    

    OR

    template <typename PAR1,
              typename PAR2 = Y>
    class Derived : public Base <PAR1> {
    };
    

    OR

    template <typename PAR1,
              typename PAR2 = Y>
    class Derived : public Base <PAR1, PAR2> {
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Following is the repetivite html structure that i have in my template: <div class=mystyle
Following this RailsCast for nested model forms: class Survey < ActiveRecord::Base has_many :questions, :dependent
Following code worked fine abstract class FunctionRunnable<V> implements Runnable { protected abstract V calculate();
following this topic: allow users to "extend" API functions class Inspector: def __init__(self, passedFunc):
Following statement runs fine under Delphi XE (Windows 7 x64) but gives Exception class
I am attempting to retrieve jpeg and jpg files using the following statement: string[]
I'm using Mercurial but I'm using the following as my branching model : I
Following are the two approaches: constructor with all the class properties Pros: I have
following is the code listed in MainClass.java. public class MainClass { public static void
Following are the features that my app is using: Screen layouts: SMALL NORMAL LARGE

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.