Declaring a default templated function

35 views Asked by At

Suppose I have the following:

// 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() {}

How do I declare the foobar function on Bar.hpp?

1

There are 1 answers

0
bolov On

The default argument must be specified just once. So do this:

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