mercredi 4 mars 2015

What's worng withe this initialization of unique_ptr?

Can somebody tell me, what is wrong with the following initialization of unique_ptr?



int main()
{
unique_ptr<int> py(nullptr);
py = new int;
....
}


g++ -O2 xxx.cc -lm -o xxx -std=c++11 says:



error: no match for ‘operator=’ (operand types are ‘std::unique_ptr<int>’ and ‘int*’)
py = new int;
^


doing



unique_ptr<int> px(new int);


just works fine.


Any hints?


Aucun commentaire:

Enregistrer un commentaire