lundi 29 février 2016

How to replace c-pointer with shared_ptr?

I am new to C++11 so please be nice.

Could you show me an easy example, how a shared_ptr can replace standard pointer? I also appreciate, an explanation if it does not make sense in that case.

e.g. Could you transform this code?

std::vector <CVariant*>liste;
liste.push_back( new CVariant( (unsigned int) 24, Parameter1", TYPE_UINT) );
std::cout << liste.at(0)->get<int>() <<"\n";
delete liste.at(0);

->

std::vector < std::shared_ptr<CVariant> >liste;

???

Aucun commentaire:

Enregistrer un commentaire