I experience a segfault on the following code:
I have an abstract class A
with a method
virtual bool Ok() const;
Now, I have the following vector
std::vector<A*> v;
filled with several pointers to existing child objects. I want to accumulate the results of the Ok()
method as follows:
std::vector<bool> results;
std::transform(v.begin(), v.end(), results.begin(), std::mem_fun(&A::Ok));
std::accumulate(results.begin(), results.end(), true, std::logical_and<bool>());
Unfortunately, I always get a segfault on the second line, and I do not understand why. Replacing the transform call by a standard C++ loop fixes the segfault. Any ideas?