I try to find method how to get non-static variable from static func?
In static function, i want to get value from non-static variable.
It is possible?
class test {
private:
static void test();
string test;
}
This is not possible. Static member functions can only access static class members. This makes sense, too, if you consider that you can invoke
test::test();
without instantiating an object. In fact, when executing the code above there may not even be a single class instance.
If you need to access non-static class members from a static member function you need to pass a class instance to it, either a pointer or a reference. When you're doing that, however, you might as well make the static member function non-static.
testinstance to your static function.