声明默认模板函数

时间:2020-07-09 04:01:55

标签: c++ default-template-argument

假设我有以下内容:

// Foo.h
struct Foo {};

// Bar.h
struct Bar {
    template <typename T, typename = typename std::enable_if<std::is_base_of<Foo, T>::value>::type>
    void foobar();
};

// Bar.hpp
// ...?
void Bar::foobar() {}

如何在Bar.hpp上声明foobar函数?

1 个答案:

答案 0 :(得分:0)

默认参数只能指定一次。这样做:

template <class T, class>
void Bar::foobar() {}