Skip to content

Commit c7b0b9d

Browse files
authored
Add files via upload
1 parent f1311a6 commit c7b0b9d

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed

decay1.cpp

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* HOME : ecourse.co.kr
3+
* EMAIL : smkang @ codenuri.co.kr
4+
* COURSENAME : C++ Template Programming
5+
* MODULE : decay1.cpp
6+
* Copyright (C) 2017 CODENURI Inc. All rights reserved.
7+
*/
8+
9+
#include <iostream>
10+
#include <type_traits>
11+
using namespace std;
12+
13+
// argument decay
14+
template<typename T> void foo(T arg) // int arg[3] = x;
15+
{
16+
// T : int*
17+
cout << typeid(T).name() << endl; // int*
18+
}
19+
20+
template<typename T> void goo(T& arg) // T : int[3] goo(int (&arg)[3])
21+
{
22+
// T : int[3]
23+
cout << typeid(T).name() << endl; // int[3]
24+
}
25+
26+
int main()
27+
{
28+
int x[3] = { 1,2,3 }; //int[3]
29+
30+
foo(x); //
31+
goo(x);
32+
33+
34+
// int y[3] = x; // error
35+
// int* p = x; // ¹è¿­ÀÇ ¿ä¼ÒÀÇ ÁÖ¼Ò..
36+
// int(&r)[3] = x; // ok..
37+
38+
39+
}
40+
41+
42+
43+
44+
45+
46+
47+
48+
49+
50+
51+

decay2.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
template<typename T> void foo(T a, T b)
3+
{
4+
}
5+
6+
template<typename T> void goo(T& a, T& b)
7+
{
8+
}
9+
10+
int main()
11+
{
12+
// "orange" : const char [7]
13+
// "apple" : const char [6]
14+
foo("orange", "apple"); // ok foo( const char*, const char*)
15+
goo("orange", "apple"); // error goo( const char [7], const char [6])
16+
}
17+

0 commit comments

Comments
 (0)