Krab
Krab

Reputation: 6756

C++ template with static_assert error

Error on line with static_assert: Expected "(" for function-style cast or type construction

#ifndef __L2P__Factory__
#define __L2P__Factory__

#include <iostream>
#include <type_traits>
#include "Initable.h"

namespace l2 {

    namespace utils {

        template <typename OBJECT, typename CTX>
        class Factory {
            static_assert(std::is_base_of<Initable<CTX>, OBJECT>, "Factory object should implement Initable protocol");
        public:
            OBJECT * create(CTX ctx);
        };

    }

}

#endif /* defined(__L2P__Factory__) */

Upvotes: 1

Views: 119

Answers (1)

jrok
jrok

Reputation: 55425

You're passing a type name to static_assert. You need a bool expression or something that convers to it. These are your options:

std::is_base_of<Initable<CTX>, OBJECT>::value
std::is_base_of<Initable<CTX>, OBJECT>{}
std::is_base_of<Initable<CTX>, OBJECT>()

Upvotes: 2

Related Questions