在std :: shared_ptr上重载运算符== [英] Overload operator== on std::shared_ptr

查看:262
本文介绍了在std :: shared_ptr上重载运算符==的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在考虑为特定类型重载std :: shared_ptr的相等性和排序运算符。因此,如果我有以下内容

I was considering overloading the equality and ordering operators of std::shared_ptr for a particular type. So if I have the following

struct Foo { /* Stuff */ };

bool operator==( const std::shared_ptr<Foo>& lhs, const std::shared_ptr<Foo>& rhs )
{
    // Do something reasonable for equality using the Foo instances
}

所以这将意味着平等不再是只是指针相等。

So this would mean equality would no longer be just pointer equality. Is there a downside or some ugly pitfall to doing this?

推荐答案

这完全是非法的,并且被Standard禁止。随之而来的是可怕的鼻恶魔。

It's completely illegal and banned by Standard. Horrible nasal demons ensue.

这篇关于在std :: shared_ptr上重载运算符==的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆