forked from pezy/CppPrimer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
58 lines (48 loc) · 1.44 KB
/
main.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
46
47
48
49
50
51
52
53
54
55
56
57
58
/***************************************************************************
* @file main.cpp
* @author Alan.W
* @date 07 Feb 2014
* @remark This code is for the exercises from C++ Primer 5th Edition
* @note
***************************************************************************/
//!
//! Exercise 16.49:
//! Explain what happens in each of the following calls:
//!
//! Exercise 16.50:
//! Define the functions from the previous exercise so that they print an
//! identifying message. Run the code from that exercise. If the calls behave
//! differently from what you expected, make sure you understand why.
//!
#include <iostream>
#include <memory>
#include <sstream>
template <typename T> void f(T)
{
std::cout << "f(T)\n";
}
template <typename T> void f(const T*)
{
std::cout << "f(const T*)\n";
}
template <typename T> void g(T)
{
std::cout << "template <typename T> void g(T)\n";
}
template <typename T> void g(T*)
{
std::cout << "template <typename T> void g(T*)\n";
}
int main()
{
int i = 42, *p = &i;
const int ci = 0, *p2 = &ci;
//g(42); //template <typename T> void g(T ); --is called
//g(p); //template <typename T> void g(T*); --is called
//g(ci); //template <typename T> void g(T) --is called
//g(p2); //template <typename T> void g(T*) --is called
//f(42); //f(T)
//f(p); //f(T)
//f(ci); //f(T)
f(p2); //f(const T*)
}