diff options
Diffstat (limited to 'sec16.1-template_func.cc')
-rw-r--r-- | sec16.1-template_func.cc | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/sec16.1-template_func.cc b/sec16.1-template_func.cc new file mode 100644 index 0000000..3c5d293 --- /dev/null +++ b/sec16.1-template_func.cc @@ -0,0 +1,22 @@ +#include <iostream> +#include <string> + +using namespace std; + +template <typename T> +int compare(const T &v1, const T &v2) +{ + if (v1 < v2) + return -1; + if (v2 < v1) + return 1; + return 0; +} + +int main(void) +{ + cout << compare(1, 0) << endl; + cout << compare(string("hi"), string("world")) << endl; + + return 0; +} |