Is it possible to access a static member function through std::for_each
?
I've hit a problem with a class I'm trying to code. I have a class Foo
which in the member section initialises an object of Boo
and I need to access this inside of a static member function that is used in std::foreach()
details below:
Foo.h
class Foo {
public:
Foo() {
w = getInstanceOfAnotherClass(0, 0); // this works fine!
}
void Transform();
static inline void processBlock(std::vector<double> &vect);
private:
std::vector<std::vector<double> > data;
Boo* w;
};
Here is the problem: Inside of the member function Transform
I have the following:
void Foo::Transform()
{
std::for_each(data.begin(), data.end(), processBlock);
}
And in ProcessBlock
I have the following:
void Foo::processBlock(std::vector<double> &vect)
{
std::vector<double> vars = w.getDataBack<double>();
}
The error that is returned is that w
invalid use of member 'w' in static member function, now, I know what the problem is.. But I don't know know of a workaround. I decided to create another function that wasn't static and then call this function from inside of processBlock
, however, the member function cannot be called without declaring an object, which, would therefore re-set the value of w
and this is not what I want.
I hope someone can help and this post isn't confusing.