support bazel complie this project and format code.

This commit is contained in:
zhangxing
2023-03-30 00:15:11 +08:00
committed by light-city
parent 1f86192576
commit 7529ae3a55
636 changed files with 10025 additions and 9387 deletions

View File

@@ -0,0 +1,30 @@
/* 模板特化.cpp */
// Eg9-6.cpp
#include <cstring>
#include <iostream>
using namespace std;
template <class T> T Max(T a, T b) { return (a > b) ? a : b; }
//特化
// template <> 返回类型 函数名<特化的数据类型>(参数表) {}
template <> const char *Max<const char *>(const char *a, const char *b) {
return (strcmp(a, b) >= 0) ? a : b;
}
template <> char *Max<char *>(char *a, char *b) {
return (strcmp(a, b) >= 0) ? a : b;
}
int main() {
float c = 5.1, d = 3.2;
char s1[] = "xyce", s2[] = "xbv";
cout << "2,3的最大值是" << Max(3, 2) << endl;
cout << "c,d的最大值是" << Max(c, d) << endl;
cout << Max("xbv", "xyce") << endl;
cout << Max(s1, s2) << endl;
}
/*
① 当程序中同时存在模板和它的特化时,特化将被优先调用;
在同一个程序中除了函数模板和它的特化外还可以有同名的普通函数。其区别在于C++会对普通函数的调用实参进行隐式的类型转换,
但不会对模板函数及特化函数的参数进行任何形式的类型转换。
*/