Interview Question:

Sample Question #251 (programming – C++)
 
Explain in detail what happens when you do not provide any constructor for a class.
Advertisements
This entry was posted in Sample Qs. Bookmark the permalink.

2 Responses to Interview Question:

  1. Brett says:

    ANSWER
     
    When no constructor is provided explicitly, the C++ compiler uses a default constructor, which is an implicit constructor that takes no arguments and does nothing. The default constructor is necessary because when an object is created, C++ always needs to call a constructor, even a degenerate one like the default constructor.
     
    At creation, the default constructor will make the object’s member variables of unknown values, because (unlike, say, Java) C++ does not allow you to inline-initialize member variables.
     
    [Note how much detail I give in the answer.]
     

  2. quant says:

    You provided a lot of detail, indeed …but it would be nice if you at least mention also copy constructor

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s