Good Morning,
I just want to know how to implement a body initilization in a class. Below is the class information.
class A
{
private:
const int size; //a const data member
char *cat;
public:
A(); //default constructor
A(const int n); //constrcutor with parameter
void print(); //print A
~A(){delete[] cat;}; //destructor
};
A::A():size(100) //head initialization of size
{
cat = new char[size];
strcpy(cat, "I see a head initialization.");
}
A::A(const int n): size(n)
{
cat = new char[n];
if (n>50)
strcpy(cat, "Meow, meow, another head initialization.");
else
cat[0]='\0';
}
void A::print()
{
cout<<"size is => "<< size<<endl;
cout<<"cat is => " <<cat<<endl;
}
Thank you