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

  • Home
  • SEARCH
  • 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 6893281
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:38:21+00:00 2026-05-27T06:38:21+00:00

Can we have a statement that calls a constructor, and does nothing with it?

  • 0

Can we have a statement that calls a constructor, and does nothing with it?

Basically, am overloading the constructor, and using the constructors without assigning it to a variable, as we would usually.
(Normally we wouldn’t do this, but I could see this arising when using functors, possibly.)

Any ideas?…. (I have declared the copy constructor as private, just to make sure that this was not the cause of the problem.)

class myClass
{
    public:
        myClass (int n, int x) { }
        myClass (int n ) { }
    private:
        myClass (const myClass & t){}  // copy constructor is private..... 
};

int main()
{
    int r = 5;
    myClass A( r );     // OK (as per usual)
    myClass ( r, r );   // OK
    myClass ( 5 );      // OK
    myClass ( r );      // not OK : error C2371: 'r' : redefinition; different basic types

    // myClass B = myClass ( r ); // this would not work as copy constructor
                                  // has been declared as private
    return 0;
}
  • 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-27T06:38:22+00:00Added an answer on May 27, 2026 at 6:38 am

    You have to say (myClass(r));, with the extra parentheses, due to the parsing rules of C++.

    (What you said is a declaration of a new variable of name r, which already exists. Note that you can also say int(r); to declare r.)

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

Sidebar

Related Questions

Anyone have a PL-SQL statement that i can use to generate database & tables
For as long as I can remember I have avoided using switch statement fall-through.
I have a variable in code that can have file path or url as
I would like to have a LINQ statement that calls the property IsValid. If
Recently I have heard the bellow statement. Can someone please elaborate on it? With
Routines can have parameters, that's no news. You can define as many parameters as
I have a program that can have a lot of parameters (we have over
I have a WCF service that is using a custom UsernamePasswordValidator. The validator needs
I know that calling a virtual method from a base class constructor can be
I have a script that calls ffprobe, parses its output and outputs it to

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.