/*类模板没有自动类型推导
* 类模板中参数类型中可以有默认参数
* 类模板中的成员函数在调用时才会加载
*/
template <class KeyType, class ValueType = string>//类模板
class MyMap {
public:
MyMap(KeyType a, ValueType name):a(a),name(name) {
}
KeyType a;
ValueType name;
};
void test() {
MyMap<string, string> wxd("wxd", "study");
MyMap<int, string> wxd2(12, "study");
MyMap<int> wxd3(13, "study");
cout << wxd.a << " " << wxd.name << endl;
cout << wxd2.a << " " << wxd2.name << endl;
cout << wxd3.a << " " << wxd3.name << endl;
}
int main() {
test();
return 0;
}
11-22
2161