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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:00:13+00:00 2026-05-25T00:00:13+00:00

I am right now reading this book , C++ templates : Complete guide. At

  • 0

I am right now reading this book , C++ templates : Complete guide. At a para i got stuck couldn’t understand the terminology , here is the para:

A fundamental principle is that any template argument must be a
quantity or value that can be determined at compile time. As becomes
clear later, this requirement translates into dramatic benefits for
the run-time costs of template entities. Because template parameters
are eventually substituted by compile-time values, they can themselves
be used to form compile-time expressions. This was exploited in the
ArrayInClass template to size the member array array. The size of an
array must be a so-called constant-expression, and the template
parameter N qualifies as such.

We can push this reasoning a little further: Because template
parameters are compile-time entities, they can also be used to create
valid template arguments. Here is an example
:

template <typename T> 
class Dozen { 
  public: 
    ArrayInClass<T,12> contents; 
};

Note how in this example the name T is both a template parameter and a
template argument. Thus, a mechanism is available to enable the
construction of more complex templates from simpler ones. Of course,
this is not fundamentally different from the mechanisms that allow us
to assemble types and functions.

I am unable to understand anything. I appreciate any help with simple and understanding words a lot.

Edit:

Arrayinclass:

template <typename T, int N> 
class ArrayInClass { 
  public: 
    T array[N]; 
};
  • 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-25T00:00:14+00:00Added an answer on May 25, 2026 at 12:00 am

    There are certain expression in C++ that are required to be known at compile time. For example:

    int someArray[30];
    

    The 30 must be a compile-time constant in C++. It could have been:

    int someArray[30 + 3];
    

    That is fine, because the compiler has all of the information necessary to compute at compile time how big to make the array. However:

    void MyFunc(int numItems) {
      int someArray[30 + numItems];
    }
    

    This is not a compile-time constant, since the user could call MyFunc with any integer value. The compiler does not know how big to make the array, so this is a compiler error.

    (note: C99 allows for the creation of arrays of arbitrary sizes like this. C++ does not).

    Because a template parameter is a compile-time value, it is possible to pass it to other places that require compile-time values:

    template<int ArrayLen> void MyFunc() {
      int someArray[30 + ArrayLen];
    }
    

    This is legal C++ because every use of MyFunc must specify a compile-time integer: the length of the array. You cannot just call MyFunc() you have to call MyFunc<21>(). And since template arguments must be compile-time determinable values, the user himself cannot provide a value that is not compile-time defined.

    Because template parameters are always compile-time defined, you can nest templates:

    template<int ArrayLen> void OtherFunc {
      MyFunc<ArrayLen + 3>();
    }
    

    This new template function calls the old one with an array 3 bigger than what it was given.

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

Sidebar

Related Questions

I'm reading the book Spring Recipes right now, and am puzzled by one thing:
I'm reading about Maven right now and everywhere in a text I see this
I am reading through a Learn C book right now and have come across
Right now I'm reading this article regarding Java Garbage Collection: http://www.javaworld.com/javaworld/jw-08-1996/jw-08-gc.html ? Here is
another request sorry.. Right now I am reading the tokens in one by one
Right now, I'm particularly interested in reading the data from MP3 files (ID3 tags?),
Right now I'm doing something like this: RewriteRule ^/?logout(/)?$ logout.php RewriteRule ^/?config(/)?$ config.php I
I'm reading a textbook right now for my Java III class. We're reading about
Right now I'm doing something like this: NSString *pullProcesses = @ps axco pid,pcpu,user,command; system([pullProcesses
I'm reading J2EE 1.4 spec right now and there are lot of terms that

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.