【发布时间】:2021-05-24 16:44:21
【问题描述】:
我正在尝试学习和使用 sfinae,这是我第一次尝试这样做。我有以下代码:
template<class CoreType, typename std::enable_if_t<std::is_base_of_v<Core, CoreType>>* = nullptr>
class Window
{
protected:
std::shared_ptr<Engine<CoreType>> _engine;
public:
virtual ~Window() = 0;
};
template<class CoreType, typename std::enable_if_t<std::is_base_of_v<Core, CoreType>>* = nullptr>
Window<CoreType>::~Window() {} // <- problem is here
我收到此错误:E0498 模板参数列表必须与参数列表匹配
似乎我应该以某种方式提供 sfinae 的虚拟参数,但如何提供?
如果我删除导致问题的, typename std::enable_if_t<std::is_base_of_v<Core, CoreType>>* = nullptr,它会正常工作,但我想学习如何使用 sfinae,我只能在 google 上找到这个特殊情况。任何人都可以帮我解决这个问题吗?谢谢
【问题讨论】:
-
en.cppreference.com/w/cpp/types/enable_if 在试图理解这个话题时帮助了我很多。
标签: c++ templates visual-c++ template-meta-programming sfinae