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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T22:50:13+00:00 2026-05-13T22:50:13+00:00

From previous post, I learnt that for there are two ways, at least, to

  • 0

From previous post, I learnt that for there are two ways, at least, to declare an array without default constructors. Like this

class Foo{
  public:
  Foo(int i) {}     
};
   Foo f[5] = {1,2,3,4,5};
   Foo f[5] = {Foo(1), Foo(2), Foo(3), Foo(4), Foo(5)}; 

I also learnt that the first one will construct the object using the parameter directly and the second copy constructor is used here. However, when I test the code below. I make the copy constructor private. I expect to see the difference of the copy constructor usage. But it is not what I expected. Neither of the two declarations is working.

class Foo{
  public:
  Foo(int i) {}     
  private:
  Foo(const Foo& f) {}
};
int main(){

   Foo f[5] = {1,2,3,4,5};
   Foo f[5] = {Foo(1), Foo(2), Foo(3), Foo(4), Foo(5)};      
}

Can anybody explain to me why does this happen?

  • 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-13T22:50:14+00:00Added an answer on May 13, 2026 at 10:50 pm

    The first won’t construct the objects directly. It will first construct a temporary Foo, and then copy the Foo into the element. It’s similar to your second way. The difference is that your second way won’t work with a explicit copy constructor, while your first will. And conversely, the first will not work with a explicit constructor taking int, while the second will. Stated another way, the first constructor used in the initialization of an element must not be explicit.

    Notice that neither way needs to copy. But they still need to check whether the copy constructors are accessible. So, they shall behave as-if they would copy, but they don’t really need to do the copy.

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

Sidebar

Related Questions

I'm trying to refresh a page without sending POST from the previous time. I've
In my previous post i ask how to create variables from an array (
I've made a previous post that tried to use a textbox. From this I
I'm trying to sort an array, from a previous post I was pointed to
I have this function from a plugin (from a previous post) // This method
From previous experience I had been under the impression that it's perfectly legal (though
From a previous question I have seen that the CLR has workstation and server
From a previous question , I learn that Linq to SQL is not able
Taken from a previous post with some modifications to respond to sepp2k 's comment
Ok so from my previous post I got a lot of good feedback. I

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.