Every class has at least one constructor function, even when none is declared.

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.
Constructors are special member function used for initializing the data elements of the object. It is executed when an object of that class is created. Constructors are automatically called when the object of the class is created. It cannot be inherited, but a derived class can call the constructor of the base class. Constructor cannot be static or virtual.

Prajakta Pandit 01-3-2017 12:45 AM

that's not correct.

Class B below has not synthesized default constructor.

class R
{
public:
R(int r){}
};

class B
{
public:
R r;
};

int _tmain(std::string argc, _TCHAR* argv[])
{ return 0;
}

athos liu 01-9-2015 07:53 AM

The answer should be "False"

You can refer to the book "Inside the C++ object model". For exmaple, if a class contains data of only primitive type, no default constructor will be created by the complier.

eddy 12-23-2014 11:53 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