dimanche 16 février 2020

Overlap raw pointer into unique_ptr and again assign it to unique_ptr

Please let me know which constructor of unique_ptr is invoked below and why?.. I am assuming that 'move constructor' is called here but I am a bit confused as in how it can be called, as the argument to move constructor requires 'r value reference' but her I am not using any r-values.

int* func1()
{
   int* p = 20;
   return p;
}

int main()
{
   std::unique_ptr<int> p = std::unique_ptr<int>(func1());
   return 0;
}

Aucun commentaire:

Enregistrer un commentaire