02
2014/08
问题C++ programming language 第309页的例子:template <class C> class Basic_ops //基本操作类
{
public:
bool operator== (const C&) const;
bool operator!= (const C&) const;
// ...
const C& derived () const //获得操作访问权
{
return static_cast <const C&> (*this);
}
};
template <class T> class Math_container : public Basic_ops < Math_container<T> > //具体实现的容器类
{
public:
size_t size() const;
T& operator[] (size_t);
const T& operator[] (size_t) const;
// ...
}; 这样,使得有关容器的基本操作定义可以与容器本身的定义分开,而且只需定义一次&n
#读书笔记
#技术帖
#c++
#cpp