19
如何删除相似的const和非const成员函数之间的代码重复?
假设class X我想在以下位置返回对内部成员的访问权限: class Z { // details }; class X { std::vector<Z> vecZ; public: Z& Z(size_t index) { // massive amounts of code for validating index Z& ret = vecZ[index]; // even more code for determining that the Z instance // at index is *exactly* the right sort of Z …