Điều gì xảy ra, Nếu gọi chức năng thành viên dễ bay hơi sử dụng đối tượng không dễ bay hơi?Gọi hàm thành viên dễ bay hơi khi không sử dụng đối tượng dễ bay hơi trong C++
#include <iostream>
using namespace std;
class A
{
private:
int x;
public:
void func(int a) volatile //volatile function
{
x = a;
cout<<x<<endl;
}
};
int main()
{
A a1; // non volatile object
a1.func(10);
return 0;
}
Nó sẽ được gọi là bình thường. –
Phrasing đẹp để tránh [this] (https://stackoverflow.com/questions/4826719/c-volatile-member-functions), [this] (https://stackoverflow.com/questions/16746070/what-does- it-mean-when-a-member-function-là-volatile) và [this] (https://stackoverflow.com/questions/2444734/what-is-the-purpose-of-a-volatile-member- function-in-c) là một dupe chính xác. – StoryTeller