Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/158.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ c++;20个概念构造函数重载_C++_Gcc_C++20_C++ Concepts_Gcc10 - Fatal编程技术网

C++ c++;20个概念构造函数重载

C++ c++;20个概念构造函数重载,c++,gcc,c++20,c++-concepts,gcc10,C++,Gcc,C++20,C++ Concepts,Gcc10,让 #包括 结构B{}; 模板 结构A{ A(int){} }; 模板 结构A{ A(bd){} }; 模板 结构C{ A A; C(bb)需要std::与:a{B}{ C(inti)需要(!std::same_as):a{i}{ }; 模板C类; int main(){} 当我试图用gcc v.10.2编译它时,我得到以下错误: #include<concepts> struct B{}; template<typename T> struct A{ A(in

#包括
结构B{};
模板
结构A{
A(int){}
};
模板
结构A{
A(bd){}
};
模板
结构C{
A A;
C(bb)需要std::与:a{B}{
C(inti)需要(!std::same_as):a{i}{
};
模板C类;
int main(){}
当我试图用gcc v.10.2编译它时,我得到以下错误:

#include<concepts>

struct B{};

template<typename T>
struct A{
  A(int) {}
};

template<>
struct A<B>{
  A(B d) {}
};

template<typename T>
struct C{
    A<T> a;
    C(B b) requires std::same_as<T, B> : a{b} {}
    C(int i) requires (!std::same_as<T, B>) : a{i} {}
};

template class C<int>;

int main() {}
main.cpp:In'C::C(B)的实例化需要与[with T=int]相同的_:
main.cpp:22:16:从这里开始需要
main.cpp:18:45:错误:调用“A::A()”时没有匹配的函数
18 | C(B)需要std::与:a{B}{}相同
|                                             ^
main.cpp:7:3:注:候选者:'A::A(int)[带T=int]'
7 | A(int){}
|   ^
main.cpp:7:5:注意:参数1从'B'到'int'没有已知的转换
7 | A(int){}
|     ^~~
main.cpp:6:8:note:candidate:'constexpr A::A(const A&)'
6 |结构A{
|        ^
main.cpp:6:8:注意:没有已知的参数1从'B'到'const A&'的转换
main.cpp:6:8:note:candidate:'constexpr A::A(A&&)'
main.cpp:6:8:注意:参数1没有从“B”到“A&&”的已知转换
但是C++20中的概念并不能阻止实例化不满足其约束条件的函数。我知道SFINAE不起作用,因为这个构造函数不是模板,但概念也应该适用于普通函数


我做错了什么?

好的,这是gcc 10.2的一个错误,我需要更新到至少10.3

这似乎是一个错误。它是从gcc10.3编译而来的
main.cpp: In instantiation of ‘C<T>::C(B) requires  same_as<T, B> [with T = int]’:
main.cpp:22:16:   required from here
main.cpp:18:45: error: no matching function for call to ‘A<int>::A(<brace-enclosed initializer list>)’
   18 |     C(B b) requires std::same_as<T, B> : a{b} {}
      |                                             ^
main.cpp:7:3: note: candidate: ‘A<T>::A(int) [with T = int]’
    7 |   A(int) {}
      |   ^
main.cpp:7:5: note:   no known conversion for argument 1 from ‘B’ to ‘int’
    7 |   A(int) {}
      |     ^~~
main.cpp:6:8: note: candidate: ‘constexpr A<int>::A(const A<int>&)’
    6 | struct A{
      |        ^
main.cpp:6:8: note:   no known conversion for argument 1 from ‘B’ to ‘const A<int>&’
main.cpp:6:8: note: candidate: ‘constexpr A<int>::A(A<int>&&)’
main.cpp:6:8: note:   no known conversion for argument 1 from ‘B’ to ‘A<int>&&’