January 2019
Intermediate to advanced
512 pages
14h 5m
English
Now, we are getting to the really interesting part of the C++ template programming—partial template specializations. When a class template is partially specialized, it remains as generic code, but less generic than the original template. The simplest form of the partial template is one where some of the generic types are replaced by concrete types, but other types remain generic:
template <typename N, typename D>class Ratio { .....};template <typename D>class Ratio<double, D> { public: Ratio() : value_() {} Ratio(const double& num, const D& denom) : value_(num/double(denom)) {} explicit operator double() const { return value_; } private: double value_;};
Here, we convert the Ratio to a double value if the numerator ...