I want to write a copy constructor for the Plane class.
class Widget{ };
class Button: public Widget{};
class Label: public Widget {};
class Plane {
vector<Widget*>vec;
public:
void Add (Widget* w) {
vec.push_back(w);
}
// need to implement copy constructor for this class???
//Plane (const Plane &obj) ???
~Plane() {
for (auto w: vec) {
delete w;
}
}
};
int main () {
Plane p1;
p1.Add(new Button);
p1.Add(new Label);
Plane p2(p1);
return 0;
}
Need your help to write a copy constructor for class Plane. Do I also need to change something in the Widget class as well? I want to have a deep copy and that's why a copy constructor is required here. I tried to write the copy constructor by myself but failed.