我只是想知道我是否可以像这样制作模板类:
template <class T> void DoSomething(T something);
但我想将它限制为仅采用浮点数或int值.可以这样做吗?
一种选择是使用boost :: enable_if,它可以用来排除模板函数的被考虑,具体取决于T代表的类型.例如,
template <class T>
typename boost::enable_if<boost::is_arithmetic<T>, void>::type DoSomething(T t);
Run Code Online (Sandbox Code Playgroud)
将模板函数限制为整数和浮点类型.
| 归档时间: |
|
| 查看次数: |
643 次 |
| 最近记录: |