vendredi 8 juillet 2016

Does default-initializing a non-const reference function parameter from a dynamically allocated dereferenced pointer create a memory leak?


I'm in front of this and will have to deal with C++98, possibly C++03, and C++11 :

type1 myfunc( type2& var = /*some value of type "type2"*/ )
{
   // Some code
}

I tried this :

type1 myfunc( type2& var = *(new type2) )
{
   // Some code
}

And of course it works, but I'm not sure wether this creates or not a memory leak. What does this code exacty do in the computer memory ? If I can't do this, do I have any other solutions than to overload my function?


Aucun commentaire:

Enregistrer un commentaire