lundi 23 février 2015

Move constructor for std::string from char*

I have a function f returning a char*. The function documentation says:



The user must delete returned string


I want to construct a std::string from it. The trivial things to do is:



char* cstring = f();
std::string s(cstring);
delete cstring;


Is it possibile to do it better using C++ features? I would like to write something like



std::string(cstring)


avoiding the leak.


Aucun commentaire:

Enregistrer un commentaire