Reputation: 181
There are some questions with the same error but no one matches with my case.
I have two classes: Loader and Processor. The loader loads a vector of string. The processor calls, in the constructor, the Loader method to load and then, for each string call its method processString. Here is the code:
class Loader
{
public:
Loader() {}
void loadAllId() { loaded_ids_.push_back("a"); }
vector<string> loaded_ids_;
};
class Processor
{
public:
Processor() {
loader_ = new Loader();
loader_->loadAllId();
vector<string> loaded = loader_->loaded_ids_;
// Here the loaded vector contains the string
for (uint i=0;i<loaded.size();i++)
processString(loaded[i]);
}
void processString(string s) { cout << s << endl; }
private:
Loader* loader_;
};
int main(int argc, char *argv[])
{
Processor* proc = new Processor();
}
Between the creation of "loaded" and the for loop that calls processStrings, the vector contains the correct strings. That is what the debug shows.
It crashes at the first call of the method processString. It doesnt even run the first line of that method.
I've tried:
Using a string instead of a string vector.
Call the Loader constructor, the loadAllId and the processString methods outside in the main function where I create the Processor.
Use directly the loader ids vector without making a copy of it (loaded).
All those changes gave me the same error at the processString call.
Upvotes: 0
Views: 2923