Why ={} initialization doesn't work for tuple?

前端 未结 2 1536
醉话见心
醉话见心 2020-12-14 16:11

To me a pair is just special case of a tuple, but following surprises me:

pair p1(1, 2);   // ok
tuple

        
2条回答
  •  青春惊慌失措
    2020-12-14 16:36

    The tuple constructor you're trying to call is explicit, so copy-list-initialization will fail. The corresponding pair constructor is not explicit.

    Change your code to

    tuple t2{1, 2};
    

    and it'll compile.

提交回复
热议问题