#include <iostream>
#include <cstring>
using namespace std;
class yunsuan
{
private:
int a, b, c;
int len,num;
char name[30];
public:
yunsuan(int d=0, int e=0, int f=0 , int r=0, int t=0) :a(d), b(e), c(f) , len(r) , num(t){strcpy_s(name,"666");};
~yunsuan() {};
void operator()(int d , int e , int f);
int &operator[](const char *m);
void operator+(yunsuan &num1);
void show(void)
{
cout << a << " " << b << " " << c << " ";
cout << " [ " << name << " ] " << " " << len << " " << num << endl;
}
void get_data(void)
{
cout << " a:" << a << " b:" << b << " c:" << c << " len:" << len << " num:" << num << " name:"<< name << endl;
}
};
void yunsuan::operator()(int d , int e , int f)
{
a = d;
b = e;
c = f;
}
int &yunsuan::operator[](const char *m)
{
len = strlen(m);
strcpy_s(this->name,m);
return this->num;
}
void yunsuan::operator+(yunsuan &num1)//加法运算重载
{
this->a += num1.a ;
this->b += num1.b ;
this->c += num1.c ;
}
int main(void)
{
int n;
cout << "输入编号:";
cin>>n;
yunsuan shu;
shu.show();
shu(1,2,3);
shu["张三"] = n;
yunsuan shu1(10,9,8);
yunsuan shu2(7,6,5);
shu+shu1;
shu.show();
system("pause");
return 0;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)