how to avoid static member function when using gsl with c++

后端 未结 4 802
小鲜肉
小鲜肉 2020-11-28 14:21

I would like to use GSL within a c++ class without declaring member functions as static. The reason for this is because I don\'t know them too well and I\'m not

4条回答
  •  情深已故
    2020-11-28 15:14

    Sorry, but what you're trying to do doesn't make any sense. Whatever thread safety issues you're worried about, they won't be solved by adding or removing the static keyword.

    The only reason why you would make g non-static would be if an instance of A was somehow required for g's operation. And g's current implementation doesn't require such an instance.

    Note you can also make g a global function, without the static keyword. There would be no visible difference in your case. However it's better style in your case to have g in the class which makes use of it, as a static function.

    Also, Here is some related material about pointers to (static/non-static) member functions.

提交回复
热议问题