operator是什么意思.在编程中

来源:学生作业帮助网 编辑:作业帮 时间:2024/05/01 06:32:40
operator是什么意思.在编程中

operator是什么意思.在编程中
operator是什么意思.在编程中

operator是什么意思.在编程中
在C++中,他是一个关键字,用于重载运算符,来实现自定义的对象运算.如:
#include
using namespace std;
class A
{
private:
int a;
public:
A() {}
A(int t):a(t) {}
friend int operator + (A a,A b) //重载了+运算符
{
return a.a + b.a;
}
};
int main(int argc,char *argv[])
{
A a(1);
A b(2);
int t;
t = a + b;
cout