在重新访问和更新任何旧图书馆时,我发现了一个非常奇怪的问题。我有以下代码
class bmint_tmp;
class bmfloat_tmp;
template<typename T> struct bop_return{typedef bmint_tmp type;};
template<> struct bop_return<float>{typedef bmfloat_temp type;};
class bmint
{
template<typename T> friend typename bop_return<T>::type operator+(const T& l, const bmint& r);
/** irrelevant code **/
};
template<typename T> typename bop_return<T>::type operator+(const T& l, const bmint& r)
{
return r.operator+(l);
}
template<> typename bop_return<bmint_tmp>::type operator+(const bmint_tmp& l, const bmint_tmp& r)=delete;我删除了这个模板实例化,因为我更喜欢调用现有的bmint_tmp::operator+,在另一个文件中作为成员方法实现。但是,在编译时,gcc似乎只看到了这个已删除的操作符,并说:error:使用已删除的函数'typename::bigmath::bop_return::type bigmath::operator+(const T&,const bigmath::bmint&) (使用T=.,我试图更改修饰符(例如,删除const规范),但我的许多尝试都失败了。有人能帮忙吗?谢谢提前感谢。
发布于 2015-05-03 16:35:19
是的,如果一个函数被删除了,那么它仍然存在(它甚至被认为是被定义的!),包含所有暗示…的内容。你真的不能这么说。
相反,使用enable_if,这样模板的专门化就不能被实例化了。那么唯一的候选将是你想要的运算符函数。
https://stackoverflow.com/questions/30016387
复制相似问题