Why variadic template constructor matches better than copy constructor?

前端 未结 3 1059
灰色年华
灰色年华 2021-01-11 20:49

The following code does not compile:

#include 
#include 

struct Foo
{
    Foo() { std::cout << \"Foo()\" << std::         


        
3条回答
  •  执念已碎
    2021-01-11 21:22

    While I agree that it's counter-intuitive, the reason is that your copy constructor takes a const Bar& but bar1 is not const.

    http://coliru.stacked-crooked.com/a/2622b4871d6407da

    Since the universal reference can bind anything it is chosen over the more restrictive constructor with the const requirement.

提交回复
热议问题