int const MyClass::MyMethod vs const int const MyClass::MyMe

int const MyClass::MyMethod vs const int const MyClass::MyMethod

本文关键字:const int MyClass MyMe MyMethod vs      更新时间:2023-10-16

有什么理由做const int const而不仅仅是String const吗?

即不使用指针。

如果你从一个函数返回字符串(例如 const string MyClass::MyMethod),你实际上最好不要使用 const,因为 const 会抑制移动语义。 这个确切的问题实际上刚刚在Microsoft的一次会议上讨论过:

http://channel9.msdn.com/Events/GoingNative/2013/Don-t-Help-the-Compiler

(适当的信息在 35 分钟左右)