The following will compile with GCC 5.2 but not with Visual Studio 2015.
template
struct CRTP {
static constexpr int num = Deriv
The problem is here:
template
struct CRTP {
static constexpr int num = Derived::value + 1;
↑↑↑↑↑↑↑↑↑
};
At the time of the instantiation of CRTP
, A
isn't a complete class yet, so you can't actually access static members of it.
One workaround is to pass in num
as a separate template argument:
template
struct CRTP {
static constexpr int num = N;
};
struct A : CRTP {
};