Possible Duplicate:
How do you use the non-default constructor for a member?
I have the current code:
class ImagePoint {
private:
int row;
int col;
public:
ImagePoint(int row, int col){
this->row = row;
this->col = col;
}
int get_row(){
return this->row;
}
int get_col(){
return this->col;
}
};
And I want to do this:
class TrainingDataPoint{
private:
ImagePoint point;
public:
TrainingDataPoint(ImagePoint image_point){
this->point = image_point;
}
};
But this wont compile because the line ImagePoint point;
requires the ImagePoint
class to have an empty constructor. The alternative (from what I have read) says I should use a pointer:
class TrainingDataPoint{
private:
ImagePoint * point;
public:
TrainingDataPoint(ImagePoint image_point){
this->point = &image_point;
}
};
However, once the constructor has finished running will this pointer point to a cleared up object? If so, do I have to make a copy of the image_point
? will this require a copy constructor?