Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在 C++ 11 中,我们鼓励将 auto 用于变量类型, 这在初始化类和向量等类型时是否也适用?
我的意思是我们应该写以下内容:
auto a = 10; auto b = MyClass(); auto c = vector<int>{1, 2, 3};
代替:
auto a = 10; MyClass b; vector<int> c = {1, 2, 3};
auto只是简化诸如此类的事情的便捷捷径
auto
VeryLongClassName *object = new VeryLongClassName();
现在它将是
auto *object = new VeryLongClassName();
没有理由写
auto a = 10; auto b = MyClass(); auto c = vector<int>();
因为它比它更长更难阅读
int a = 10; MyClass b; vector<int> c;