//
//基本数据类型的运算符不允许被重载
#include <iostream>
using namesapce std;
/*
int operator+(int,int)
{
return a - b;
}
*/
//不允许创造运算符
class Integer
{
int x;
public:
Integer(int x= 0):x(x)
{
//不能创造运算符
//int operator#() {return x;}
//运算符的最基本规则不可以被改变,比如不能将双目运算符重载成单目运算符,运算符
/*
friend Integer operator%(const Integer& i1)
{
return Integer(x%10);
}
*/
}
};
int main()
{
int x = 10;
int y = 20;
int z = x + y;
}
基本数据类型的运算符不能重载,不能创造运算符
最新推荐文章于 2022-04-02 13:51:34 发布