1
如何为具有std :: enable_if参数的模板类编写外联析构函数体?已启用 - 如果类中的析构函数的行外定义?
(我需要这个写一个装饰器,为其他对象类型添加一个标识符)。
代码:
template<typename T,
typename std::enable_if<std::is_base_of<X,T>::value>::type* = nullptr>
class IdentifiedInstance: public T
{
public:
virtual ~IdentifiedInstance() = 0; // abstract base, still needs a function body
};
主体定义:
template<typename T,
typename std::enable_if<std::is_base_of<X,T>::value>::type* = nullptr>
IdentifiedInstance::~IdentifiedInstance()
{
}
这并不编译,因为IdentifiedInstance::
应该IdentifiedInstance<T, ???>::
。
这里的第二个参数值是什么? 如何正确写入?
注意事项(1):
的Visual Studio 2015年接受这种形式:
template<typename T,
typename std::enable_if<std::is_base_of<X,T>::value>::type* = nullptr>
class IdentifiedInstance: public T
{
public:
~IdentifiedInstance() = 0
{
}
};
不幸的是我写的代码需要也可以在linux下建(和gcc理所当然扼流圈这种形式)。
备注(2):我试过在线搜索,但是我发现的大部分答案都是关于如何部分专门化析构函数的。