這可能只是該概念不好,但我不明白爲什麼。並沒有找到任何與構造函數的例子。或者,也許它沒有任何關係的構造......C++概念:CRTP
template < typename T >
concept bool C_Object() {
return requires {
T();
};
}
template < C_Object Object>
class DefaultManager {
// Content;
};
template < C_Object Derived >
class Component {
// Content
};
struct Test : public Component<Test> {
int data;
Test() = default;
};
int main() {
Test test;
return 0;
}
給錯誤:
test2.cpp:21:36: error: template constraint failure
struct Test : public Component<Test> {
^
test2.cpp:21:36: note: constraints not satisfied
test2.cpp:2:14: note: within ‘template<class T> concept bool C_Object() [with T = Test]’
concept bool C_Object() {
^~~~~~~~
test2.cpp:2:14: note: the required expression ‘T()’ would be ill-formed
這聽起來像一個:「嘿,我的代碼是壞了,請修復它」,對不起。
反正感謝
有一個偉大的日子
你知道概念沒有達到標準嗎? – SergeyA
@SergeyA是可能C++ 20 –