c++比较运算符重载函数_compare

来源:互联网 发布:怎样去开淘宝店 编辑:程序博客网 时间:2024/06/03 22:44

1. 函数参数可以任意类型的

2. 返回值是bool类型

3. 编译器没有提供默认实现,不能直接使用?

#define COMPARE(_op_)                                           /
inline bool operator _op_ (const sp<T>& o) const {              /
    return m_ptr _op_ o.m_ptr;                                  /
}                                                               /
inline bool operator _op_ (const wp<T>& o) const {              /
    return m_ptr _op_ o.m_ptr;                                  /
}                                                               /
inline bool operator _op_ (const T* o) const {                  /
    return m_ptr _op_ o;                                        /
}                                                               /
template<typename U>                                            /
inline bool operator _op_ (const sp<U>& o) const {              /
    return m_ptr _op_ o.m_ptr;                                  /
}                                                               /
template<typename U>                                            /
inline bool operator _op_ (const wp<U>& o) const {              /
    return m_ptr _op_ o.m_ptr;                                  /
}                                                               /
template<typename U>                                            /
inline bool operator _op_ (const U* o) const {                  /
    return m_ptr _op_ o;                                        /
}

原创粉丝点击