class Record{
public:
Record():number(0){}
Record(int num):number(num){}
void init(int num){number=num;}
int number;
};
class Student{
public:
Student(){
ptr_rec=new Record(10);//allowed
rec.init(10);//allowed
Record rec(10);//allowed but a difference object, therefore no good
rec(10);//not allowed
}
~Student(){
delete ptr_rec;
}
void viewStudent(){
std::cout<<rec.number<<std::endl;
}
private:
Record rec;
Record *ptr_rec;
};
My question is: without going to the heap, or using an init() function, is it possible to initialize a constructor with arguments, in another constructor? And if not why not.