add Chapter08
This commit is contained in:
16
Chapter08/template_function.cpp
Normal file
16
Chapter08/template_function.cpp
Normal file
@@ -0,0 +1,16 @@
|
||||
#include <cstdio>
|
||||
|
||||
template<typename T>
|
||||
T add(T a, T b) {
|
||||
return a + b;
|
||||
}
|
||||
|
||||
int main() {
|
||||
int result_int = add(1, 4);
|
||||
float result_float = add(1.11f, 1.91f);
|
||||
|
||||
printf("result_int = %d\r\n", result_int);
|
||||
printf("result_float = %.2f\r\n", result_float);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user