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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:55:48+00:00 2026-05-29T09:55:48+00:00

Why does this work? char __nontype[] = foo; typedef TemplateClass<T, __nontype> MyClass; But this

  • 0

Why does this work?

char __nontype[] = "foo";
typedef TemplateClass<T, __nontype> MyClass;

But this (with a constant variable) not?

const char __nontype[] = "foo";
typedef TemplateClass<T, __nontype> MyClass;

Compiler Error:

error: ‘__nontype’ cannot appear in a constant-expression

error: template argument 2 is invalid

  • 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-29T09:55:49+00:00Added an answer on May 29, 2026 at 9:55 am

    The difference is because const affects the linkage. It works if you add extern. That said, as far as I can tell:

    14.3.2 Template non-type arguments [temp.arg.nontype]

    A template-argument for a non-type, non-template template-parameter shall be one of:

    • an integral constant expression (including a constant expression of literal class type that can be used as an integral constant expression as described in 5.19); or
    • the name of a non-type template-parameter; or
    • a constant expression (5.19) that designates the address of an object with static storage duration and external or internal linkage or a function with external or internal linkage, including function templates and function template-ids but excluding non-static class members, expressed (ignoring parentheses) as & id-expression, except that the & may be omitted if the name refers to a function or array and shall be omitted if the corresponding template-parameter is a reference; or
    • a constant expression that evaluates to a null pointer value (4.10); or
    • a constant expression that evaluates to a null member pointer value (4.11); or
    • a pointer to member expressed as described in 5.3.1.

    it should also work without extern. The object is allowed to have internal linkage, but your compiler does not yet support that. This is one of the changes in C++11, the previous C++ standard did not allow it.

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

Sidebar

Related Questions

1- How does this work: char *ptr = hi; Now the compiler will put
Why does this not work as expected? int main() { unsigned char louise, peter;
Why this does not work with groovy? ('a' as char) ^ ('b' as char)​
In Guile 1.6.*, the function scm_istring2number(char *str,int strlen,int radix) does the work. However, this
Why does this not work? Do I not understand delegate covariance correctly? public delegate
I've done this before with inputs, why on earth does this not work? http://euroworker.no/user/checkout
This does NOT work: Sub X() Dim A As Access.Application Set A = CreateObject(Access.Application)
When you make a string out of char pointers how does this work? char
How does the following code work? typedef char (&yes)[1]; typedef char (&no)[2]; template <typename
Why does this work: //split returns (char**) char *temp2; temp2=split(array[i],'=')[1]; and this doesn't: char

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.