forked from codenuri/TEMPLATE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfriend4.cpp
45 lines (38 loc) · 892 Bytes
/
friend4.cpp
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
/*
* HOME : ecourse.co.kr
* EMAIL : smkang @ codenuri.co.kr
* COURSENAME : C++ Template Programming
* MODULE : friend4.cpp
* Copyright (C) 2017 CODENURI Inc. All rights reserved.
*/
#include <iostream>
using namespace std;
/*
template<typename T> class Point
{
T x, y;
public:
Point() : x(0), y(0) {}
Point(T a, T b) : x(a), y(b) {}
friend ostream& operator <<(ostream& os, const Point<T>& p);
};
*/
// 컴파일러가 생성한 코드..
class Point
{
int x, y;
public:
Point() : x(0), y(0) {}
Point(int a, int b) : x(a), y(b) {}
friend ostream& operator <<(ostream& os, const Point<int>& p);
};
template<typename T>
ostream& operator <<(ostream& os, const Point<T>& p)
{
return os << p.x << ", " << p.y;
}
int main()
{
Point<int> p(1, 2);
cout << p;// operator<<(cout, p) => operator<<(ostream, Point<int> )
}