【发布时间】:2012-07-22 17:47:42
【问题描述】:
我的问题如下
template<class T> MyClass
{
MyClass(/* Lots of parameters with no problem */, const T& min = 0, const T& max = std::numeric_limits<T>::max());
set(/* Lots of parameters with no problem */, const T& min = 0, const T& max = std::numeric_limits<T>::max());
/* Lots of function with no problem */
}
我希望我的模板类与std::string 兼容,而无需重新实现所有功能。对于 std::string 我想要min = "" 和max = ""。目前,它崩溃为 0 例如不能转换为字符串。怎么做 ? (如果我只能专门化构造函数和主设置器,那就太好了)。
【问题讨论】:
-
兼容的意思是:如果
T == std::string应该很好玩,或者MyClass应该是std::string的直接替代品?
标签: c++ class templates specialization