本文介绍了在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
发布评论