删除的操作员隐藏了类操作员

deleted operator hides class operator?

本文关键字:操作员 隐藏 删除      更新时间:2023-10-16

我在重新访问和更新任何旧库时发现了一个非常奇怪的问题。我有以下代码

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 ,在另一个文件中以成员方法的形式实现。但是,在编译时,似乎海湾合作委员会除了删除了操作员外什么都没有看到,并说:错误:使用已删除函数'typeName :: BigMath :: Bop_return :: type bigmath :: operator (const t&amp;,const bigmath :: bmint&amp;)[带有t = ... >我试图更改修饰符(例如,删除const规范),但是我的许多尝试都没有成功。谁能帮忙?预先感谢。

是的,如果删除了一个函数,则它仍然存在(甚至被认为是定义的!),所有内容都暗示&Hellip;您实际上无法称呼它。

使用enable_if,而是根本无法实例化模板专业化。那么唯一的候选人将是您想要的操作员功能。