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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T01:30:38+00:00 2026-06-11T01:30:38+00:00

I am working on a project which handles the Data of a Library Section

  • 0

I am working on a project which handles the Data of a Library Section having multiple classes. Interface of interest of a class here is this.

class Author
{
  private:
    //data members
  public:
    Author (string _name) ;
    Author (string _name, int _books) ;
} ;

Data is present with at least the name of the author, and no. of books may come along. I cannot have a default constructor here naturally. But if create a static array like this.

Author auth_arr[100] ;

Compiler gives me error due to absence of default constructor. But this statement is invalid as well.

Author auth_arr[100] ("Jacob") ; 

Is there any method by which i can create this array and call the constructor of my choice, instead of making another method?

  • 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-11T01:30:40+00:00Added an answer on June 11, 2026 at 1:30 am

    You can do this to a very limited extent. The trick is to call those constructors explicitly inside curly braces inside separated by commas, and instantiate the static array this way.

    Author auth_arr [3] = {Author(“Kevin”, 7) ,Author(“Martha”) ,Author(“Shuan”, 15) } ;
    

    But this method is literally a nightmare. You can do this for a size 5 or 10 array but not for a 50 size array or any more than that. So the better option is to make another method and call it passing the details as its arguments. Remember this is only for static arrays as you asked. For dynamic arrays, which are more frequently used than static, even this method is not applicable.

    C++ does not allow you another method to call constructors of your choice. So default constructor should be defined in the class to get called at instantiation. Then, an appropriate method could be called afterwards with the data.

    Another better thing would be to use std :: vector. Its detail you can find in another similar question here.
    Constructors and array of object in C++

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

Sidebar

Related Questions

Im working on a Project which Handles with File information's ,like Tool-tips File Attributes
Can anyone help me find an up-to-date, working ATL project which has a main
Iam working on a project which involves writing a Mork File (Mork is a
I'm working on a project which contains several slave nodes and one master node.
I'm working on a project which involves two processes, let them be A and
I started working on a project which uses Net_URL_Mapper from PEAR (php) as the
I'm working on a project which needs to use youtube api. The html and
I am working on a project which lists file sharing urls from the likes
I am working on a project which uses OsmAnd for the maps. I am
I'm working on a project which uses user authentication. I'm facing a issue with

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.