小编cv3*_*000的帖子

(C++)这些重载的运算符函数有什么区别?

下面这两种重载!=运算符的方法有什么区别.哪个更好?

Class Test  
{  
...//
private:  
int iTest

public:  
BOOL operator==(const &Test test) const;
BOOL operator!=(const &Test test) const;  
}

BOOL operator==(const &Test test) const  
{  
    return (iTest == test.iTest);  
}    

//overload function 1  
BOOL Test::operator!=(const &Test test) const  
{  
    return !operator==(test);  
}

//overload function 2  
BOOL Test::operator!=(const &Test test) const  
{  
    return (iTest != test.iTest);  
}  
Run Code Online (Sandbox Code Playgroud)

我刚刚看到函数1的语法用于调用兄弟运算符函数,并想知道是否以这种方式编写它会带来任何好处.

c++ overloading class function operators

2
推荐指数
1
解决办法
510
查看次数

标签 统计

c++ ×1

class ×1

function ×1

operators ×1

overloading ×1