mercredi 27 avril 2016

Correct way to type casting in c++11 style?

So i have a class like this:

A{
init(int a){
_data.resize(a); //! (1)
}
//other code is unimportant
private:
std::list<std::vector<double>> _data;
}

In (1) i got warning with text: implicit conversion from int to size_type(aka unsigned long)

I want to know what is most correct way to get rid of that warning? Maybe something like that:

_data.resize(static_cast<decltype(_data)::size_type>(a)

note :

I guess that this :

init(size_t a) 

is the right way, but let us assume that we can not change interface

Aucun commentaire:

Enregistrer un commentaire