template <class V, class K>
class Pair {
public:
Pair(const K& key, const V& value = initial) { // what should "initial" be here?
// ...
}
}
例如,如果我使用这样的类:
int main() {
Pair<int, std::string> p1(21); // p1 should be {21, ""} as the default value of a string is "".
Pair<int, double> p2(20); // p2 should be {20, 0.0} assuming the default value of a double is 0.0
}
我怎样才能做到这一点?