-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathfriend5.cpp
More file actions
45 lines (38 loc) · 891 Bytes
/
friend5.cpp
File metadata and controls
45 lines (38 loc) · 891 Bytes
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 : friend5.cpp
* Copyright (C) 2017 CODENURI Inc. All rights reserved.
*/
#include <iostream>
using namespace std;
// 해결책 1.
// 클래스와 friend 함수
// 1 : 1,
// 1 : N,
// N : 1,
// N : N =>
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);
// 함수 템플릿.
template<typename U>
friend ostream& operator <<(ostream& os, const Point<U>& 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 << endl;
}