作业帮 > 综合 > 作业

operator是什么意思.在编程中

来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/05/08 11:00:15
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