내가 여기에 CRTP 템플릿 클래스가 있습니다그 소리가 : constexpr 변수가 가질 수없는 비 문자 유형
template <typename S>
class Base
{
public:
constexpr static S NOT_SET{0};
};
struct Derived : public Base<Derived>
{
};
연타 (5.0.0)이이 동의하지 않습니다
5 : <source>:5:24: error: constexpr variable cannot have non-literal type 'const Derived'
constexpr static S NOT_SET{0};
^
8 : <source>:8:25: note: in instantiation of template class 'Base<Derived>' requested here
struct Derived : public Base<Derived>
^
5 : <source>:5:24: note: incomplete type 'const Derived' is not a literal type
constexpr static S NOT_SET{0};
^
8 : <source>:8:8: note: definition of 'Derived' is not complete until the closing '}'
struct Derived : public Base<Derived>
^
1 error generated.
Compiler exited with result code 1
그러나 gcc (4.9.2와 6.2에서 테스트)는 괜찮습니다.
clang에서이 작업을 수행하는 방법은 무엇입니까?
고마워요. 그러나 GCC의이 "기능"을 악용하는 기존 코드베이스를 포팅하려는 경우, 귀하의 충고는 무엇입니까? – Anton
파생 된 유형이 constexpr 구성 가능하면, 기본 클래스에서 _not set_ 버전을 반환하는 constexpr 함수를 정의 할 수 있습니다 (의미하는대로). 그것은 당신을 위해 일할 수 있을까요? – skypjack
네, 좋은 생각입니다. 고맙습니다. 나는 당신의 대답을 받아 들일 것이지만, 당신은 후손을 위해 당신의 대답을 대답에 넣을 수 있다고 생각합니까? :-) – Anton