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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T02:33:14+00:00 2026-06-01T02:33:14+00:00

Let’s say I have the class Foo . The following works fine: class Foo

  • 0

Let’s say I have the class Foo. The following works fine:

class Foo
{
    public:
        const int* bar;

        Foo()
        {
            bar = new int[2] {1, 2};
        }
};

However, I tried to change this very slightly to use a template:

template<int A, int B>
class Foo
{
    public:
        const int* bar;

        Foo()
        {
            bar = new int[2] {A, B};
        }
};

My understanding of the way templates work is that A and B are essentially compile time constants, so it should still work the same.

The error message I get when compiling with g++ (4.5 in the link, same error with 4.6.3) is:

error: ISO C++ forbids initialization in array new [-fpermissive]

With 4.7 a similar error occurs, though slightly different:

error: parenthesized initializer in array new [-fpermissive]

The problem also occurs in template functions, and not just when template parameters are used within the braces for initialization, code and output. (thanks Philipp)

  • 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-01T02:33:16+00:00Added an answer on June 1, 2026 at 2:33 am

    Looks like this is a GCC bug. Clang accepts it, and the standard allows it:

    new-initializer:

    ( expression-listopt)
    braced-init-list

    And the rules for this initialization are not special:

    A new-expression that creates an object of type T initializes that
    object as follows:

    — If the new-initializer is omitted, the object is
    default-initialized (8.5); if no initialization is performed, the
    object has indeterminate value.

    — Otherwise, the new-initializer is
    interpreted according to the initialization rules of 8.5 for direct-initialization.

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

Sidebar

Related Questions

Let's say you have a class called Customer, which contains the following fields: UserName
Let's say I have the following models class Photo(models.Model): tags = models.ManyToManyField(Tag) class Tag(models.Model):
Let's suppose we have: Class Foo{ int x,y; int setFoo(); } int Foo::setFoo(){ return
Let's say on a page I have alot of this repeated: <div class=entry> <h4>Magic:</h4>
Let's say I have the following text: (example) <table> <tr> <td> <span>col1</span> </td> <td>col2</td>
Let's say I have the following object: var VariableName = { firstProperty: 1, secondProperty:
Let's say I have one class User, and it has a property of type
Let's say you have a class library project that has any number of supplemental
Let's say I have an abstract parent class called shape, and that there are
Let's say I have the string: hello world; some random text; foo; How could

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.