//b=a+2의 + 연산자 재작성
/*
#include<iostream>
using namespace std;
class Power
{
int kick;
int punch;
public:
Power(int kick = 0, int punch = 0);
void show();
Power operator+(int op2);
};
Power::Power(int kick, int punch)
{
this->kick = kick;
this->punch = punch;
}
void Power::show()
{
cout << "kick = " << kick << ", punch = " << punch << endl;
}
Power Power::operator+(int op2)
{
Power tmp;
tmp.kick = kick + op2;
tmp.punch = punch + op2;
return tmp;
}
int main()
{
Power a(3, 5), b;
a.show();
b.show();
b = a + 2;
a.show();
b.show();
}*/
//전위 ++연산자 재작성
/*
#include<iostream>
using namespace std;
class Power
{
int kick;
int punch;
public:
Power(int kick = 0, int punch = 0);
void show();
Power& operator++();
};
Power::Power(int kick, int punch)
{
this->kick = kick;
this->punch = punch;
}
void Power::show()
{
cout << "kick = " << kick << ", punch = " << punch << endl;
}
Power& Power::operator++()
{
kick++;
punch++;
return *this;
}
int main()
{
Power a(3, 5), b;
a.show();
b.show();
b = ++a;
a.show();
b.show();
}*/
//Power 클래스에 ! 연산자 작성
/*
#include<iostream>
using namespace std;
class Power
{
int kick;
int punch;
public:
Power(int kick = 0, int punch = 0);
void show();
bool operator!();
};
Power::Power(int kick, int punch)
{
this->kick = kick;
this->punch = punch;
}
void Power::show()
{
cout << "kick = " << kick << ", punch = " << punch << endl;
}
bool Power::operator!()
{
if (kick == 0 && punch == 0)
{
return true;
}
else
{
return false;
}
}
int main()
{
Power a(0, 0), b(5, 5);
if (!a)
{
cout << "a의 파워가 0이다." << endl;
}
else
{
cout << "a의 파워가 0이 아니다." << endl;
}
if (!b)
{
cout << "b의 파워가 0이다." << endl;
}
else
{
cout << "b의 파워가 0이 아니다." << endl;
}
}*/
//후위 ++ 연산자 작성
/*
#include<iostream>
using namespace std;
class Power
{
int kick;
int punch;
public:
Power(int kick = 0, int punch = 0);
void show();
Power operator++(int x);
};
Power::Power(int kick, int punch)
{
this->kick = kick;
this->punch = punch;
}
void Power::show()
{
cout << "kick = " << kick << ", punch = " << punch << endl;
}
Power Power::operator++(int x)
{
Power tmp = *this;
kick++;
punch++;
return tmp;
}
int main()
{
Power a(3, 5), b;
a.show();
b.show();
b = a++;
a.show();
b.show();
}*/
//2+a를 위한 + 연산자 함수를 프렌드로 작성
/*
#include<iostream>
using namespace std;
class Power
{
int kick;
int punch;
public:
Power(int kick = 0, int punch = 0);
void show();
friend Power operator+(int op1,Power op2);
};
Power::Power(int kick, int punch)
{
this->kick = kick;
this->punch = punch;
}
void Power::show()
{
cout << "kick = " << kick << ", punch = " << punch << endl;
}
Power operator+(int op1, Power op2)
{
Power tmp;
tmp.kick = op1 + op2.kick;
tmp.punch = op1 + op2.punch;
return tmp;
}
int main()
{
Power a(3, 5), b;
a.show();
b.show();
b = 2+a;
a.show();
b.show();
}*/
//a+b를 위한 +연산자 함수를 프렌드로 작성
/*
#include<iostream>
using namespace std;
class Power
{
int kick;
int punch;
public:
Power(int kick = 0, int punch = 0);
void show();
friend Power operator+(Power op1, Power op2);
};
Power::Power(int kick, int punch)
{
this->kick = kick;
this->punch = punch;
}
void Power::show()
{
cout << "kick = " << kick << ", punch = " << punch << endl;
}
Power operator+(Power op1, Power op2)
{
Power tmp;
tmp.kick = op1.kick + op2.kick;
tmp.punch = op1.punch + op2.punch;
return tmp;
}
int main()
{
Power a(3, 5), b(4, 6), c;
a.show();
b.show();
c = a + b;
c.show();
}*/
//++연산자 함수를 프렌드로 작성
/*
#include<iostream>
using namespace std;
class Power
{
int kick;
int punch;
public:
Power(int kick = 0, int punch = 0);
void show();
friend Power& operator++(Power& op);
friend Power operator++(Power& op, int x);
};
Power::Power(int kick, int punch)
{
this->kick = kick;
this->punch = punch;
}
void Power::show()
{
cout << "kick = " << kick << ", punch = " << punch << endl;
}
Power& operator++(Power& op)
{
op.kick++;
op.punch++;
return op;
}
Power operator++(Power& op, int x)
{
Power tmp = op;
op.kick++;
op.punch++;
return tmp;
}
int main()
{
Power a(3, 5), b;
b = ++a;
a.show();
b.show();
b = a++;
a.show();
b.show();
}*/
//참조를 리턴하는 <<연산자 작성
/*
#include<iostream>
using namespace std;
class Power
{
int kick;
int punch;
public:
Power(int kick = 0, int punch = 0);
void show();
Power& operator<<(int n);
};
Power::Power(int kick, int punch)
{
this->kick = kick;
this->punch = punch;
}
void Power::show()
{
cout << "kick = " << kick << ", punch = " << punch << endl;
}
Power& Power::operator<<(int n)
{
kick += n;
punch += n;
return *this;
}
int main()
{
Power a(1, 2);
a << 3 << 5 << 6;
a.show();
}*/