본문 바로가기

c++

c++ operator 연산자 구현

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <iostream>
using namespace std;
 
class A{
 
    int a;
public:
    A(int a = 0) {
 
        this-> a = a;
    }
 
    void setA(int a) {
        this->= a;
    }
 
    int getA() {
        return a;
    }
 
    friend  ostream & operator << (ostream & out, A &aa);
    //friend ostream & operator >> (ostream &in, A &aa);
    friend istream & operator >> (istream & in, A &aa);
}; 
 
ostream & operator << (ostream & out, A &aa) {
 
    out << aa.a;
    return out;
}
 
 istream & operator >> (istream & in, A &aa) {
 
      in >> aa.a;
      return in;
 }
void main() {
 
    A aa(100);
    A bb;
 
    cin >> aa >> bb;
    cout << aa << bb;
    
}
 
cs

 

'c++' 카테고리의 다른 글

c++ public protected private  (0) 2018.12.31
reference 레퍼런스 계산기 구현  (0) 2018.12.31
c++ 동적 계산기 구현 ver1  (0) 2018.12.31
c++ string을 나만의 것으로 구현  (0) 2018.12.31