显式成员函数特化
Explicit member function specialisation
我无法特化下面的模板成员函数。我查看了为回答关于 SOF 的类似问题而给出的解决方案,但提出的解决方案与我在下面的代码相同,但它似乎不起作用。我肯定遗漏了一些东西。
enum EStep
{
eStep1, eStep2, eStep3
};
template<int16_t iDevice>
struct Device
{
template<EStep step>
static constexpr bool isType() { return false; }
};
template<> template<>
constexpr bool Device<int16_t>::isType<eStep1>()
{
return true;
}
template<> template<>
constexpr bool Device<int16_t>::isType<eStep1>()
{
return true;
}
Device 是 int16_t 的模板,因此要专门化它,您需要提供一个 int16_t 值作为模板参数。例如
template<> template<>
constexpr bool Device<999>::isType<eStep1>()
我无法特化下面的模板成员函数。我查看了为回答关于 SOF 的类似问题而给出的解决方案,但提出的解决方案与我在下面的代码相同,但它似乎不起作用。我肯定遗漏了一些东西。
enum EStep
{
eStep1, eStep2, eStep3
};
template<int16_t iDevice>
struct Device
{
template<EStep step>
static constexpr bool isType() { return false; }
};
template<> template<>
constexpr bool Device<int16_t>::isType<eStep1>()
{
return true;
}
template<> template<>
constexpr bool Device<int16_t>::isType<eStep1>()
{
return true;
}
Device 是 int16_t 的模板,因此要专门化它,您需要提供一个 int16_t 值作为模板参数。例如
template<> template<>
constexpr bool Device<999>::isType<eStep1>()