成员函数无法访问易失性成员
volatile member can not be accessed by member function
以下代码使我的程序崩溃:
#include <string>
#include <vector>
class test {
volatile std::vector<std::string> wtf;
public:
test() {}
void dope() { wtf.clear(); }
};
int main(){
(new test())->dope();
return 0;
}
我不知道为什么。当我删除易失性时,它会再次工作。那么为什么易失性是一个问题呢?
std::vector::clear()
没有volatile
限定符。
因此,用挥发性载体称呼它是非法的。
顺便说一句,volatile
不是多线程的神奇关键字。
您可以使用mutex
来保护对载体的访问。
相关文章:
- 易失性sig_atomic_t的内存安全性
- C++易失性:保证 32 位访问?
- 避免易失性和非易失性成员函数的代码重复
- 当 2 个线程共享同一物理内核时,具有错误共享的易失性增量在发布中的运行速度比在调试中慢
- 如何访问常量易失性 std::array?
- 为什么在 C++20 中弃用易失性?
- 根据 MSVC,具有易失性成员的结构不再是 POD
- 是否允许编译器优化掉局部易失性变量
- 访问共享内存而不使用易失性、std::atomic、信号量、互斥锁和自旋锁
- C++:易失性实例中的易失性成员函数 - 将数组分配给指针是无效的转换?
- 成员函数无法访问易失性成员
- 易失性数据成员是易于复制的
- 如何用libclang找出成员函数是常量还是易失性
- C++中易失性成员函数与常量成员函数的比较
- 易失性关键字在C++中成员函数声明中的位置
- 易失性成员函数 (C++)
- 易失性成员的访问方法
- 为什么易失性对象不能调用非易失性成员函数
- 你能从易失性函数中抛弃成员上的易失性吗>
- 为什么易失性静态成员初始化会生成重新定义编译错误