-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path48.cpp
56 lines (48 loc) · 1.18 KB
/
48.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
#include <iostream>
#include <sstream>
using std::ostringstream;
using std::cout;
using std::endl;
#include <string>
using std::string;
// always declared first
template <typename T> string debug_rep(const T& t);
template <typename T> string debug_rep(T* p);
string debug_rep(const string& s);
string debug_rep(char* s);
string debug_rep(const char* s);
template<typename T> string debug_rep(const T &t){
ostringstream ret;
ret << "const T &t " << t;
return ret.str();
}
template <typename T> string debug_rep(T* p){
ostringstream ret;
ret << "pointer: " << p;
if(p){
ret << "if p";
ret << "->" ;
// ret << debug_rep(*p);
} else {
ret << "null pointer";
}
return ret.str();
}
string debug_rep(const string &s){
return "nontemplate--" + s ;
}
string debug_rep(char* s){
return debug_rep(string(s));
}
string debug_rep(const char* s){
return debug_rep(string(s));
}
int main(){
string s("hi");
//cout << debug_rep(s) << endl;
// cout << debug_rep(&s) << endl;
//const string *sp = &s;
//cout << debug_rep(sp) << endl;
// cout << debug_rep(s) << endl;
cout << debug_rep("hello, world!") << endl;
}