C++/따배C++ 09강 연산자 오버로딩
[C++/9.03] 단항 연산자 오버로딩
polarcompass
2021. 10. 28. 01:26
728x90
#include <iostream>
#include <fstream>
using namespace std;
class Cents
{
private:
int m_cents;
public:
Cents(int cents = 0) { m_cents = cents; }
int getCents() const { return m_cents; }
int &getCents() { return m_cents; }
Cents operator+(const Cents &c2)
{
return Cents(this->m_cents + c2.getCents());
}
bool operator ! () const
{
return (m_cents == 0) ? true : false;
}
friend std::ostream &operator<<(std::ostream &out, const Cents ¢s)
{
out << cents.m_cents;
return out;
}
};
int main()
{
Cents cents1(6);
Cents cents2(0);
auto temp = !cents1;
auto temp2 = cents1;
cout << !cents1 << ' ' << !cents2 << endl;
}
728x90