c++ - 共享库中是否应该避免使用静态成员函数?

标签 c++ c static global-variables shared-libraries

在阅读 Oliveira 和 Stewart 合着的《Writing Scientific Software》一书时,我看到了一段有趣的文章:

"Shared variables are dangerous and should be avoided in shared libraries

So if you are writing a shared or dynamically linked library, avoid static or saved local variables and avoid global variables."

(page 55)

但是 static 成员函数呢?这些在共享库中是否同样危险?我也应该避免这些吗?为什么/为什么不?

最佳答案

But what about static member functions? Are these equally as dangerous in a shared library?

一点也不:static 成员函数不应避免:与表示共享状态的 static 变量不同,static 成员函数表示共享计算.只要这些计算是无状态,它们就一点都不危险。

关于c++ - 共享库中是否应该避免使用静态成员函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13244876/

相关文章:

c++ - 你能继承同一个类两次吗?

c++ - Code::Blocks/Dev-c++: 错误: iostream: 没有那个文件或目录

c - 当我多次运行我的程序(用 C 语言)时,它总是选择相同的随机数

c - 递归:在其位置反转字符串

c++ - 如何在构造函数和析构函数中增加模板类中的静态 int 值?

c++ - 静态变量会减慢应用程序的启动时间

c++ - 通过指针访问 std::vector 元素与 end()

CUDA代码无法进入while循环

objective-c - 不在静态 UIViewController 子类中调用 [super dealloc]

c++ - 编译错误(g++ 和 make)