开发者

If I declare an instance variable as volatile, will the object of this class be volatile?

开发者 https://www.devze.com 2023-03-24 05:08 出处:网络
Like: class A { volatile int i; }; A a; My question is that will the entire a become cv开发者_StackOverflow qualified? May be a naive question.No, all of a will not be volatile.Just as you can ha

Like:

class A
{
     volatile int i;
};


A a;

My question is that will the entire a become cv开发者_StackOverflow qualified? May be a naive question.


No, all of a will not be volatile. Just as you can have fields of a class that are const without every instance of the class being const, you can have volatile fields that do not make the entire class instance volatile.

0

精彩评论

暂无评论...
验证码 换一张
取 消