Yes it really is.
Although in most cases, having a non-static member is better, static members are sometimes used in cases where you need to pass a pointer to an external library, for example, in your case for the pthread library.
If it makes sense to change this private variable in other situations, and if you want to separate your class from the fact that it uses the pthread library, you can split the class into two:
- one class that handles functionality (e.g. your class)
- one class that handles interaction with pthread
The second class will then set the variable in the first class using the public method.
Example: this is probably your source code:
class MyClass { public: static void someMethod(MyClass *); private: type myMember; };
and you can also write it:
class MyClass { public: void setMember(type value) {myMember = value; } private: type myMember; } class MyClassPThreadInterface { public: static void someMethod(MyClass *myclass) {myclass->...();} }
Thus, you completely separate your class from the fact that it is used by the PThread library. This makes it suitable for use in other cases (where the static method is rather pointless), and it is also easy to add another stream library (for example, Windows threads) without polluting the source class.
source share