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
Get step-by-step solutions from verified subject matter experts
