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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T11:40:58+00:00 2026-06-14T11:40:58+00:00

What is the effect of the const keyword in this template? template <class T,

  • 0

What is the effect of the const keyword in this template?

template <class T, int const ROWNUM, int const COLNUM> 
class Matrix

Does it mean that this template only accept a const as parameter? If so, is there a way to pass a variable as the COLNUM and ROWNUM?

(when I try to pass a variable as the COLNUM for the template, it gives an error: “IntelliSense: expression must have a constant value”)

  • 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-14T11:41:00+00:00Added an answer on June 14, 2026 at 11:41 am

    It’s ignored:

    [C++11: 14.1/4]: A non-type template-parameter shall have one of the following (optionally cv-qualified) types:

    • integral or enumeration type,
    • pointer to object or pointer to function,
    • lvalue reference to object or lvalue reference to function,
    • pointer to member,
    • std::nullptr_t.

    [C++11: 14.1/5]: [ Note: Other types are disallowed either explicitly below or implicitly by the rules governing the form of template-arguments (14.3). —end note ] The top-level cv-qualifiers on the template-parameter are ignored when determining its type.

    The same wording is present at the same location in C++03.

    This is partially because template arguments must be known at compile-time anyway. So, whether you have the const there or not, you may not pass some variable value:

    template <int N>
    void f()
    {
        N = 42;
    }
    
    template <int const N>
    void g()
    {
        N = 42;
    }
    
    int main()
    {
        f<0>();
        g<0>();
    
        static const int h = 1;
        f<h>();
        g<h>();
    }
    

    prog.cpp: In function ‘void f() [with int N = 0]’:
    prog.cpp:15: instantiated from here
    prog.cpp:4: error: lvalue required as left operand of assignment
    prog.cpp: In function ‘void g() [with int N = 0]’:
    prog.cpp:16: instantiated from here
    prog.cpp:10: error: lvalue required as left operand of assignment
    prog.cpp: In function ‘void f() [with int N = 1]’:
    prog.cpp:19: instantiated from here
    prog.cpp:4: error: lvalue required as left operand of assignment
    prog.cpp: In function ‘void g() [with int N = 1]’:
    prog.cpp:20: instantiated from here
    prog.cpp:10: error: lvalue required as left operand of assignment

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

Sidebar

Related Questions

I have an effect that when you hover over this one particular area, it
How to store Effect parameters in class ? I'm stuck in this problem for
consider the code template <class A> class B; template <class A> class B<const A>{};
Is there a side effect in doing this: C code: struct foo { int
Have a look at this hypothetical header file: template <class T> class HungryHippo {
Skitch has this nice effect where it will draw its text on a white
Perhaps this is an effect of installing the new 4.5 beta, but my simulator
I have an effect file in XNA4, being compiled as Shader Model 3. This
Scriptaculous's Effect.Morph can take a CSS class and apply it over a period of
public sealed class IntegerBox : TextBox { #region constants private const string RangeConstraintValidatorID =

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.