Implicit conversion from int to shared_ptr

后端 未结 3 1274
Happy的楠姐
Happy的楠姐 2021-01-12 19:36

Consider the code below:

#include 
#include 

void f(std::shared_ptr sp) {}

template 

        
3条回答
  •  一个人的身影
    2021-01-12 19:57

    The firs call f(0) is compiled as f(nullptr), which is fine for the compiler (but it should not be in my opinion). The second call will create declaration for a function to work on any int, which is illegal.

    Funny thing is, that even this code works:

    f(3-3);
    f(3*0); 
    

提交回复
热议问题