这是我想做的伪代码。
template<typename T>
struct ConvertToT
{
static_assert(false, "Explicit specialization for T required.");
// Variant will be coerced to this type before calling Convert.
std::uint32_t GetVariantType()
{
return VT_EMPTY;
}
T Convert(CComVariant& input)
{
return "ERROR!";
}
};
template<>
struct ConvertToT<std::wstring>
{
std::uint32_t GetVariantType()
{
return VT_BSTR;
}
T Convert(CComVariant& input)
{
return std::wstring(input.bstrVal, ::SysStringLen(input.bstrVal));
}
};
/* repeat for several more explicit specializations:
* template<>
* struct ConvertToT<...>
* {
* std::uint32_t GetVariantType()
* {
* return ...;
* }
* ... Convert(CComVariant& input)
* {
* return ...;
* }
* };
*/
有什么方法可以禁用主模板并需要使用明确的专业化?