In: Computer Science
Given the class below, which answer choice would be an implementation of the default constructor (without an initialization list)?
class MyInteger {
private:
int num;
public:
MyInteger();
MyInteger(int newint);
void setInt(int newint);
int getInt();
int operator[](int index);
};
MyInteger::MyInteger(int newNum) { num = newNum; }
MyInteger::MyInteger() { num = 0; }
MyInteger::MyInteger(int newNum = 0) { num = newNum; }
MyInteger::MyInteger(int newNum) : num{0} {;}
MyInteger::MyInteger(int newNum = 0) : num{0} {;}
MyInteger::MyInteger() : num{0} {;}
MyInteger::MyInteger(newNum) { num = newNum; }
Given MyInteger class definition:
class MyInteger {
private:
int num;
public:
MyInteger();
MyInteger(int newint);
void setInt(int newint);
int getInt();
int operator[](int
index);
};
------------------------------------------------------------------------------
The default constructor for the class MyInteger is
MyInteger::MyInteger()
{
num = 0;
}
------------------------------------------------------------------------------
Default constructor : A constructor
contains the class name same as class name and it does not take any
arguments or parameters and set the default values like 0 for
integer,float and double and empty for string type variables.
Therefore, the correct option is
MyInteger::MyInteger()
{
num = 0;
}