在《Effective C++》第44条:Factor parameter-independent code out of templates。我发现它的英文版和侯捷翻译的中文版有些不同。
这是我在第 214 页找到的英文版:
template<typename T> // size-independent base class for
class SquareMatrixBase { // square matrices
protected:
...
void invert(std::size_t matrixSize); // invert matrix of the given size
...
};
template<typename T, std::size_t n>
class SquareMatrix: private SquareMatrixBase<T> {
private:
using SquareMatrixBase<T>::invert; // make base class version of invert
// visible in this class; see Items 33
// and 43
public:
...
void invert() { invert(n); } // make inline call to base class
}; // version of invert
在侯捷翻译的中文版中。除了倒数第二行之外,前面几行代码几乎相同:
void invert() { this->invert(n); }
在中文版中,侯杰解释了使用this->invert(n)
instead of的原因invert(n)
:模板化基类的函数名会隐藏在派生类中。
我认为这可能是错误的,因为using SquareMatrixBase<T>::invert;
已经在派生类的其他部分添加了。
但我想,侯捷作为一个著名的翻译家,不会轻易犯这么明显的错误,这次他真的错了吗?