O'Reilly logo
  • LI WEI thinks this is interesting:

Inside a class, you can add the const keyword to a member function declaration. What the const keyword does is promises to the compiler that the internal state of the object will not change as a result of running this function. Attaching the const keyword will look something like this:

From

Cover of Learning C++ by Creating Games with UE4

Note

在get函数中,建议加const保证返回的变量不会修改