This code works:
class Test
{
public:
Test(string name) : _name(name) {};
bool operator()() { cout << "hello " << _name << endl; return true; }
string name() { return _name; }
private:
string _name;
};
pair<string, bool>
inline execute_test(Test* t) {
return pair<string, bool>(t->name(), (*t)());
}
int main()
{
vector<Test*> tests;
vector<pair<string, bool> > results;
tests.push_back(new Test("Test1"));
tests.push_back(new Test("Test2"));
for (unsigned int i=0; i < tests.size(); ++i)
results.push_back(execute_test(tests[i]));
}
now I want to use trasform instead of the for cicle:
transform(tests.begin(), tests.end(),
results.begin(),
execute_test);
but I got a Segmentation Fault. Where is the problem?