的右侧),如果放在返回类型的顶级,则忽略code> volatile code>如果它是一个指针),因为这些返回值不对应于内存,可能也保存在寄存器中的实现)。将 volatile 放在非顶层引用或指针可能非常有用,如下面Putting volatile on a return value can be done too, but it seems to me that it would be less useful since return values are usually temporaries and volatile semantics are quite on the the opposite scale of temporaries. Putting volatile on void is particularly nonsensical (const and volatile are ignored if put at the top-level of a return type if the type is not a class type (i.e at the right of a * if it is a pointer), because these return values do not correspond to memory, likely being kept in registers by implementations too). Putting volatile on non-toplevel for references or pointers can be useful, like in the followingstruct Controller { HWOverlayClock volatile const* getClock() const { return clock; }private: volatile const HWOverlayClock *clock;};希望它有帮助。 这篇关于多少使用“易失性”关键字有C ++函数,从语法的角度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-28 18:09