I'm stock on this problem and all the solutions that I found here doesn't work for me.
First, I have this class:
class Flow {
public:
Flow();
...
virtual double execute() = 0;
...
private:
...
};
That's working fine in my subclass tests. And I also have this Class:
class Model {
public:
Model();
...
Model(const Model& mdl);
Model& operator=(const Model& mdl);
...
private:
string name;
vector<Flow*> flows;
...
};
And in the copy constructor, i have to copy the Flow* vector to another Flow* vector, and I'm doing this:
Model& Model::operator =(const Model& mdl) {
this->name = mdl.name;
this->flows.resize(mdl.flows.size());
for (unsigned int i = 0; i < mdl.flows.size(); i++) {
*this->flows[i] = *mdl.flows[i];
}
return *this;
}
But isn't working. I can't initialize a empty Flow object at this point, because the execute() method is pure virtual;
I tried to use transform(), but the clone() method needs to implement the Flow();
What I'm doing wrong?
UPDATE: This way works:
Model& Model::operator =(const Model& mdl) {
this->name = mdl.name;
for (unsigned int i = 0; i < mdl.flows.size(); i++) {
Flow *cp = (Flow*) malloc(sizeof(mdl.flows[i]));
this->flows.push_back(cp);
}
return *this;
}