Constructors for C++ objects
- by sasquatch
I have class Person as following :
class Person {
char* name;
int age;
};
Now I need to add two contructors. One taking no arguments, that inserts field values to dynamically allocated resources. Second taking (char*, int) arguments initialized by initialization list. Last part is to define a destructor showing information about destroying objects and deallocating dynamically allocated resources. How to perform this task ?
That's what I already have :
class Person {
char* name;
int age;
public:
Person(){
this->name = new *char;
this->age = new int;
}
Person(char* c, int i){
}
};