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

The Archive Base Latest Questions

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

I know that there is no return type of the constructors in C++ However,

  • 0

I know that there is no return type of the constructors in C++

However, the code below compiles right. What is returned by the constructor in the code below?

class A{

public:
A() {}
}


A a = A();      //what is returned by A() here, why?

Is there any conflict here?

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

    Nothing is returned from the constructor. The syntax A() is not a constructor call, it creates a temporary object of type A (and calls the constructor in the process).

    You can’t call a constructor directly, constructors are called as a part of object construction.

    In your code, during the construction of the temporary the default constructor (the one you defined) is called. Then, during the construction of a, the copy constructor (generated automatically by the compiler) is called with the temporary as an argument.

    As Greg correctly points out, in some circumstances (including this one), the compiler is allowed to avoid the copy-construction and default-construct a (the copy-constructor must be accessible however). I know of no compiler that wouldn’t perform such optimization.

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

Sidebar

Related Questions

I'm building a little helper to turn EF4 objects to POCOs. (I know there
I currently have an immutable type called Gene , that only has 2 fields:
Let's say that I have an adt representing some kind of tree structure: data
Is there an accepted method of adding possibly-derived objects to a collection without allowing
I have a class Matrix which contains ArrayList<ArrayList<Double>> matrix; inside, and I want to
Let's say I have three value constructors: A { a :: Int } B
I'm a completely new to C++ and I'm having a very stupid problem. I
I'm currently trying to do a homework, and I'm trying to get my things
Possible Duplicate: How to check internet access on Android? InetAddress never timeouts I need
I'm trying to create a custom ActionFilter which operates on a set of parameters

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.