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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T19:13:55+00:00 2026-06-09T19:13:55+00:00

When compiling the code below with gcc, I get an error: ‘i’ cannot appear

  • 0

When compiling the code below with gcc, I get an error: ‘i’ cannot appear in a constant-expression.

Why is this?

#include <iostream>

using namespace std;
template<int p>
class C
{
public:
    void test();
};

template<int p>
void C<p>::test()
{
    p = 0;
}

char const *const p = "hello";
int main()
{
    const int i = (int)p;
    C<i> c;
}
  • 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-09T19:13:57+00:00Added an answer on June 9, 2026 at 7:13 pm

    The variable i is not mutable at runtime because it is const, but it is not a “constant expression” because it is not evaluated at compile-time.

    (int)p; is a reinterpret_cast. Integral constant expressions cannot have reinterpret_cast. It is explicitly forbidden (§5.19/2):

    A conditional-expression is a core constant expression unless it
    involves one of the following as a potentially evaluated subexpression
    (§3.2), but subexpressions of logical AND (§5.14), logical OR (§5.15),
    and conditional (§5.16) operations that are not evaluated are not
    considered [Note: An overloaded operator invokes a function.—end
    note
    ]:

    — […]

    — a reinterpret_cast (§5.2.10);

    — […]

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

Sidebar

Related Questions

How can I get rid of this error and other while compiling the below
When compiling the code below, I get the following error: PersonalInformation is not abstract
Compiling this code with g++ 4.7.0 ( -Wall -Wextra -Werror -Wconversion -std=c++11 ): #include
I am compiling following code and getting following error. How to fix this? Thanks
I've got error C2078 in VC2010 when compiling the code below. struct A {
I don't know why but this code below gives this error in debug mode
When compiling the code below with cl /c /clr /W4 the compiler says warning
I got some quite strange errors compiling code under gcc. It tells me that
I am compiling my code with gcc 4.7.0. My code compiles fine with 4.6.1.
I have the following piece of code compiling under gcc: int parseMsg(const char *msg_to_parse,

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.