在阅读C++ Primer, 5th Edition中一个练习的答案时,我发现了以下代码:
#ifndef CP5_ex7_04_h
#define CP5_ex7_04_h
#include <string>
class Person {
std::string name;
std::string address;
public:
auto get_name() const -> std::string const& { return name; }
auto get_addr() const -> std::string const& { return address; }
};
#endif
什么是IT技术?
const -> std::string const&
在这种情况下,mean 是什么意思?
auto func() -> type
=type func()
,但前者具有更多功能。在你的情况下,它没有优势,很可能是因为编写代码的人喜欢它比正常语法更多。 - HolyBlackCat