这种使用模板的方式是否合法?
有没有另一种编译时和异常安全的方法?
class Foo {};
class Bar : public Foo {};
//Only accept classes, which inherit Foo.
template<Foo T>
void awesomeFunction() {
Foo *f = new T();
}
int main() {
awesomeFunction<Bar>();
}
有没有另一种编译时和异常安全的方法?
template <class T>
,而不是其他的。 - SirGuy