if constructor is not declared, the compiler assumes the class to have a default constructor with no arguments

Options
- True
- False


CORRECT ANSWER : True

Discussion Board
C++ - Constructors

The above answer is true. Every class has at least one constructor. If you do not mention or write a constructor for a class, C++ generates one constructor for you which is known as Default constructor. It is not visible in your code, but it is available there.

Prajakta Pandit 01-24-2017 04:21 AM

Default constructor

Based on the wording of the statement, that the compiler "assumes the class to have a default constructor", I'd say that the answer should be false.

Generally, when one "assumes" something to be or not, they ignore the thing and move on. The compiler makes no "assumptions" when it comes to a default constructor. It will create one if the programmer hasn't.

From cppreference.com…

"If no user-defined constructors of any kind are provided for a class type (struct, class, or union), the compiler will always declare a default constructor as an inline public member of its class.

"If the implicitly-declared default constructor is not deleted or trivial, it is defined (that is, a function body is generated and compiled) by the compiler, and it has exactly the same effect as a user-defined constructor with empty body and empty initializer list. That is, it calls the default constructors of the bases and of the non-static members of this class.


gds 06-12-2014 06:41 AM

Write your comments


Enter the code shown above:

(Note: If you cannot read the numbers in the above image, reload the page to generate a new one.)


Advertisement