草庐IT

non-volatile

全部标签

c++ - 为什么不能实例化带有 "non const"复制构造函数的对,而没有实例化一对是可能的?

假设您有以下类(class):structA{A(){}A(A&)=delete;};intmain(){std::pairp1;return0;}以下代码将无法编译(使用-std=c++11和g++)并出现以下错误:/usr/include/c++/5/bits/stl_pair.h:Ininstantiationof‘structstd::pair’:test.cpp:13:23:requiredfromhere/usr/include/c++/5/bits/stl_pair.h:127:17:error:‘constexprstd::pair::pair(conststd::pa

c++ - 错误 : invalid initialization of non-const reference of type ‘bool&’ from an rvalue of type ‘std::vector<bool>::reference {aka std::_Bit_reference}’

为什么我会收到错误:从类型为“std::vector::reference{akastd::_Bit_reference}”的右值对类型为“bool&”的非常量引用进行无效初始化?vector>vis;bool&visited(intx,inty){returnvis[x][y];//error}据我所知,vector中的operator[]返回引用,所以它应该是一个左值,但它不起作用。我应该怎么做才能让它发挥作用? 最佳答案 那是因为std::vector不是它看起来的样子。std::vector有一个特化与类型bool-它是空间

C++ : Why cant static functions be declared as const or volatile or const volatile

这个问题在这里已经有了答案:关闭10年前。PossibleDuplicate:C++-Whystaticmemberfunctioncan’tbecreatedwith‘const’qualifier想知道为什么静态成员函数不能声明为const或volatile或constvolatile的原因?#includeclassTest{staticvoidfun()const{//compilererrorreturn;}};

c++ - 具有类型 'const CompareVPtrs' 的表达式将丢失一些 const-volatile 限定符以便调用

我正在用C++实现十五个益智控制台游戏,引发了以下错误Error4errorC3848:expressionhavingtype'constCompareVPtrs'wouldlosesomeconst-volatilequalifiersinordertocall'boolCompareVPtrs::operator()(Vertex*,Vertex*)'c:\programfiles\microsoftvisualstudio11.0\vc\include\xfunctional3241puzzle15这是我的结构structCompareVPtrs:publicbinary_fu

c++ - volatile 数据成员是否可以轻松复制?

写作时thisanswer我意识到我对自己的结论没有信心,因为我通常会在点击发布您的答案之前确保这一点。对于volatile数据成员的平凡可复制性要么是实现定义的,要么是完全不允许的论点,我可以找到一些相当有说服力的引文:https://groups.google.com/forum/?fromgroups=#!topic/comp.std.c++/5cWxmw71ktIhttp://gcc.gnu.org/bugzilla/show_bug.cgi?id=48118http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#

C++ volatile 对象,非 volatile 成员

在问题中:假设我有一小段这样的代码:#includeusingnamespacestd;structfoo{inta;foo():a(12){};};intmain(){volatilefoox;return0;}用g++-g-O2编译事实证明,x初始化被优化掉了。但是那个:#includeusingnamespacestd;structfoo{volatileinta;foo():a(12){};};intmain(){volatilefoox;return0;}调用构造函数。如果我尝试在代码中使用变量(即cout),两种情况下的汇编输出是等效的。我是否正确理解以下内容:在第一种情况

c++ - volatile 未按预期工作

考虑这段代码:structA{volatileintx;A():x(12){}};Afoo(){Aret;//Dostuffreturnret;}intmain(){Aa;a.x=13;a=foo();}使用g++-std=c++14-pedantic-O3我得到了这个程序集:foo():movl$12,%eaxretmain:xorl%eax,%eaxret根据我的估计,变量x应该至少被写入三次(可能是四次),但它甚至没有被写入一次(函数foo不是甚至打电话!)更糟糕的是,当您将inline关键字添加到foo时,结果如下:main:xorl%eax,%eaxret我认为volatil

c++ - 铿锵错误 : non-type template argument refers to function that does not have linkage -- bug?

我有一些非常简单的(C++11)代码,最新的clang(version3.4trunk187493)无法编译,但GCC编译正常。代码(下面)实例化函数模板foo使用局部函数类型Bar然后尝试将其地址用作类模板Func的非类型模板参数:templatestructFunc{};templateexterninlinevoidfoo(){usingFoo=Func>;}intmain(){structBar{};//function-localtypefoo();return0;}clang发出以下错误:error:non-typetemplateargumentreferstofunct

c++ - volatile 限定符是否取消了此内存的缓存?

在本文中:http://www.drdobbs.com/parallel/volatile-vs-volatile/212701484?pgno=2说,我们不能对volatile做任何优化,即使是(where:volatileint&v=*(address);):v=1;//C:writetovlocal=v;//D:readfromv无法对此进行优化:v=1;//C:writetovlocal=1;//D:readfromv//butitcanbedoneforstd::atomic这是不可能完成的,因为在第1行和第2行之间v值可能会被硬件设备更改(不是CPU无法工作的缓存一致性:网

c++ - 如果我声明一个实例变量为volatile,这个类的对象会不会是volatile?

喜欢:classA{volatileinti;};Aa;我的问题是整个a成为cv合格吗?可能是一个幼稚的问题。 最佳答案 不,所有a都不会volatile。正如您可以拥有一个const的类的字段,而无需该类的每个实例都是const,您可以拥有不是const的volatile字段使整个类实例volatile。 关于c++-如果我声明一个实例变量为volatile,这个类的对象会不会是volatile?,我们在StackOverflow上找到一个类似的问题: ht