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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:26:52+00:00 2026-06-18T05:26:52+00:00

Can one overload a constructor with a private constructor with the same parameters? Basically

  • 0

Can one overload a constructor with a private constructor with the same parameters?

Basically if something stores a positive integer, then in the public constructor it would make sure a positive integer was being stored, whereas in a private constructor it doesn’t perform the check.

Obviously this example isn’t really an appropriate use, but sometimes you want to create an object inside a method and you don’t want it to waste time performing full safe initialisation; you may want to just tell it to create something straight away without the special checks (or more prudently heap allocations or something expensive) when you’re going to perform them again later or they’re just unnecessary, and a method inside the class should be able to use this constructor automatically instead of the other public one with the same parameters.

  • 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-18T05:26:53+00:00Added an answer on June 18, 2026 at 5:26 am

    You cannot overload on acccess like private versus public, but you can overload on the signature: the number of arguments and their types.

    Private constructors are quite common.

    One usage is for a logically “deleted” constructor (finally directly supported by C++11), and another is for use by a public factory function.


    Example:

    class A
    {
    public:
        A( int const x)
        {
            // Whatever, checked construction.
            // Perform the check of the x argument.
            // Then other things.
            // In C++11 it can be done by checking x and forwarding to the
            // unchecked constructor in the same class. Not shown here though.
        }
    
    private:
        enum unchecked_t { unchecked };
        A( int const x, unchecked_t )
        {
            // Unchecked construction.
        }
    
        // Methods that possibly use the unchecked constructor.
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can one accomplish class-based default value in following scheme? I mean, I would
Coming from C++ background ;) How can I overload PHP functions? One function definition
Can one place an arbitrary program (firefox, openoffice, etc...) in a QX11EmbedContainer? The fllowing
Can one of you smarties point me to some beginner content for converting an
Can one upload files to a domain other than the domain a script originates
Can one call a method from another model in a model in CodeIgniter? I
Can one transaction update two different TVar s in an atomic way? i.e. can
How can one tell, given a void * pointer, what is the size of
How can one make recursive Glob() in a VariantDir() environment in Python? The answer
How can one call a ColdFusion function, passing in attribute values as arguments, inside

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.