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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T00:06:10+00:00 2026-06-06T00:06:10+00:00

In my studies, I have learned that if you want to prevent users from

  • 0

In my studies, I have learned that if you want to prevent users from calling the default constructor of a class, you can make it private:

class Person
{
public:
  Person(const Person&);
  ~Person();
private:
  Person();  //Any call to this will cause a compiler error.
};

What I don’t understand is when I create an uninitialized array of the class, it gives me a syntax error saying that it is private:

Person * ptr;   //Works just fine.
Person arr[1];  //Syntax error: 'Person::Person()' is private

This would leave me to believe that it makes an attempt to call the default constructor when the array is created. But this doesn’t make any sense to me since I’m not actually creating any real objects.

  • 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-06T00:06:11+00:00Added an answer on June 6, 2026 at 12:06 am
    Person * ptr;   //Works just fine. 
    Person arr[1];  //Syntax error: 'Person::Person()' is private 
    

    This would leave me to believe that it makes an attempt to call the
    default constructor when the array is created. But this doesn’t make
    any sense to me since I’m not actually creating any real objects.

    Here is your mistake. In your second example (the one that fails) you are creating a real object. You are defining an array of Persons (people?!) with one element/object.

    Therefore you are creating an object to go into that array.

    Remember when an object gets created – what happens?
    A constructor is called, if there is no suitable definied constructor what does the compiler
    do?

    It uses the default one – but it cannot because it is private.

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

Sidebar

Related Questions

I have such a structure: single profile can attend do several studies and for
I have profiles and studies. One person can finish many studies. The form renders
I have a table Studies that I perform a SELECT on. I then need
I have a dataset composed of values obtained from studies and experiments. Experiments are
I have the following models: class Keyword < ActiveRecord::Base has_many :tags has_many :studies, :through
I have a database that contains participant contact information for studies: homePhone, altPhone, and
I have written an application that essentially sniffs an Ethernet Device, and studies certain
I have a simple form that looks like this: <%= simple_form_for @study,:url => studies_path,
I have studied that The inline specifier is a hint to the compiler that
We have studied the Variable Elimination recently and the teacher emphasizes that it is

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.