我写了以下内容:
//Policy Classes
template
<typename T>
struct CheckForZeroSpeed
{
};
template
<typename T>
struct NoCheck
{
};
//Specialization for one of the Policy Classes
template
<>
struct NoCheck<float>
{
};
//Class that uses Policy
template
<typename T,template <class C> class Policy>
class Base : public Policy<T>
{
};
//Inherited class that uses Policy
template
<typename T,template <class C> class Policy>
class Derived : public Base<T,Policy>
{
};
如何声明Base类的特化(比如说int
类型)和Derived类的特化?
这也有效:
template
<>
class Base<int,NoCheck>
{
};
但这是一个基于类型和策略的专业化,它是否只能基于两个模板参数中的一个(类型)进行专业化?类似的东西:
//not compile
template
<template <class C> class Policy>
class Base<int,Policy<T>>
{
};
修改 正确的是:
//Partial specialization based on the type
template
<template <class C> class Policy>
class Base<int,Policy>
{
};
//Partial specialization based on the Policy
template
<typename T>
class Base<T,NoCheck>
{
};