学了这么多年C++今天拜读scott meyes的more effective cpp第一次看到这种写法... 引用限定可以让成员函数只能被左值对象调用或者只能被右值对象调用: #include <iostream> struct Test { void workLvalue() & { std::cout << " work only if object was a lvalue\n"; } void workRvalue() && {…
以pass-by-reference-to-const 替换pass-by-value 考虑以下class继承体系 class Person { public: Person(); // parameters omitted for simplicity virtual ~Person(); // see Item 7 for why this is virtual ... private: std::string name; std::string address; }; class Stud…