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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T05:56:50+00:00 2026-06-16T05:56:50+00:00

g++ 4.7 supports array member initialization and I started playing with it. The code

  • 0

g++ 4.7 supports array member initialization and I started playing with it.

The code below does not compile.

struct A
{
   A(int){};
   A(const A&) = delete;
   A& operator=(const A&) = delete;
   ~A(){};
};

struct B
{
   B():
      a{{0},{1}}
   {};
   A a[2];
};

B b;

The error message with gcc 4.8 (prerelease) is:

n.cc: In constructor ‘B::B()’:
n.cc:12:20: error: use of deleted function ‘A::A(const A&)’
           a{{0},{1}}
             ^
n.cc:4:8: error: declared here
        A(const A&) = delete;
        ^

Is there a way to make this code work? I can’t easily change the contructors,destructor of A.
I seem to need a move-constructor or copy-constructor to initialize the array, but this seems counter-intuitive, since all I really want is in-place construction.

It works if I split a[2] in 2 members a0 and a1, and construct them separately. This looks fishy however.

  • 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-16T05:56:51+00:00Added an answer on June 16, 2026 at 5:56 am

    Arrays are aggregates, and aggregate initialization always uses copy initialization. C++11 §8.5.1/1:

    An aggregate is an array or a class with no user-provided constructors, no brace-or-equal-initializers for non-static data members, no private or protected non-static data members, no base classes, and no virtual functions.

    §8.5.1/2:

    When an aggregate is initialized by an initializer list, as specified in 8.5.4, the elements of the initializer list are taken as initializers for the members of the aggregate, in increasing subscript or member order. Each member is copy-initialized from the corresponding initializer-clause. …

    (Emphasis mine.)

    Additionally, the compiler does not implicitly generate a move constructor if a user-declared copy constructor is present (§12.8/9); because you have a user-declared copy constructor that is defined as deleted, A has neither a copy nor a move constructor. Explicitly adding a move constructor works:

    struct A
    {
       A(int) { }
       A(A const&) = delete;
       A& operator = (A const&) = delete;
       A(A&&) = default;
       ~A() = default;
    };
    
    struct B
    {
       B() : a{{0}, {1}} { }
       A a[2];
    };
    
    int main()
    {
       B b;
    }
    

    Online demo

    This is about as close to what you want as you’re going to get.

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

Sidebar

Related Questions

Native Array in Emberjs does not support deep copy? I saw it just returning
I read that Python does not actually support 2D arrays but rather an array
I use an external module ( libsvm ), which does not support numpy arrays,
pspell Is there a way to get an array of dictionaries that pspell supports,
Official PHP documentation states that filter_var_array() supports array filtering in the following format: $data
I'm rewriting some existing code in a setting where recursive calls are not easily
My question is related to this thread. Here is the code #include <stdio.h> int
The following bit of C++11 code: std::array<float, 3> A; Gets an error message: array
How to implement a stack using array that supports items of different type. e.g.
BigQuery supports repeating, array columns. These can be expanded (flattened) by using the FLATTEN

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.