Marco A.
Marco A.

Reputation: 43662

is_base_of in a template parameter - class does not name a type

Just wondering why I can't use is_base_of in a C++ template argument like the following:

#include <iostream>
#include <type_traits>
using namespace std;

struct base
{
};

struct derived : public base
{
    int value;
};




template<class A, class B, bool isbaseof = std::is_base_of<A,B>::value> myclass
{
    void foo() {
        cout << "Generic..";
    }
};

template<class A, class B> myclass<A,B,true>
{
    void foo() {
        cout << "A is not base of B";
    }
};

int main() {

    return 0;
}

Error:

prog.cpp:17:73: error: ‘myclass’ does not name a type
 template<class A, class B, bool isbaseof = std::is_base_of<A,B>::value> myclass

Where am I getting wrong?

Upvotes: 0

Views: 1281

Answers (1)

Kerrek SB
Kerrek SB

Reputation: 477378

You forgot the class key:

   template<class A, class B, bool isbaseof = std::is_base_of<A, B>::value>
   struct myclass
// ^^^^^^

(The class key can be any of class, struct or union.)

Upvotes: 8

Related Questions