繁体   English   中英

成员函数无法访问volatile成员

[英]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;
}

我不明白为什么。 当我删除volatile时,它会再次运行。 那么为什么挥发性问题呢?

std::vector::clear()没有volatile限定符。

因此,使用volatile向量调用它是非法的。

BTW, volatile不是多线程的神奇关键字。
您可以使用mutex来保护对矢量的访问。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM