#include <iostream>
using namespace std;
class Person
{
friend const Person operator * (const Person &l,const Person &r);
private:
int a;
int b;
public:
Person(){}
Person(int a,int b):a(a),b(b){}
void show()
{
cout << "a=" << a << "b" << b << endl;
}
// const Person operator*(const Person &p) const
// {
// Person temp;
// temp.a = a * p.a;
// temp.b = b * p.b;
// return temp;
// }
};
const Person operator * (const Person &l,const Person &r)
{
Person temp;
temp.a=l.a*r.a;
temp.b=l.b*r.b;
return temp;
}
int main()
{
Person p1(10,20);
Person p2(20,3);
Person p3 = p1 * p2;
p3.show();
return 0;
}
#include <iostream>
using namespace std;
class Person
{
friend const Person operator / (const Person &l,const Person &r);
private:
int a;
int b;
public:
Person(){}
Person(int a,int b):a(a),b(b){}
void show()
{
cout << "a=" << a << "b" << b << endl;
}
// const Person operator / (const Person &p) const
// {
// Person temp;
// temp.a = a / p.a;
// temp.b = b / p.b;
// return temp;
// }
};
const Person operator / (const Person &l,const Person &r)
{
Person temp;
temp.a=l.a / r.a;
temp.b=l.b / r.b;
return temp;
}
int main()
{
Person p1(10,21);
Person p2(2,3);
Person p3 = p1 / p2;
p3.show();
return 0;
}