Question: 3. When you define a class in C++, and do not provide any constructor, then the default constructor will be used. Please type in the

3. When you define a class in C++, and do not provide any constructor, then the default constructor will be used. Please type in the following code, add necessary header files, compile and run the code, and a main function with a call to the operator << and answer the question based on your observation.

How does the default constructor initialize the member variables for us?

the int member variable:

the double member variable:

the array variable:

the char variable:

class YourClassName

{

public:

friend ostream & operator<< (ostream & outs, const YourClassName & o)

{

outs << o.value << endl;

outs << o.dvalue << endl;

for (int i=0; i<10; i++)

outs <<"a["<

outs << o.c << endl;

return outs;

}

private:

int value;

double dvalue;

int a[10];

char c;

};

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!