I encountered a compilation error when trying to initialize a vector of pointers to NULL
by way of the std::vector
constructor. I simplify the instruction to keep it simple:
vector<int*> v (100,NULL)
I guess it has something to do with an incompatibility between const T& value= T()
(the parameter of the constructor) and the very value NULL, but I would appreciate some further explanation.
Thank you
NULL
is likely defined as0
, so you end up withwhich tries to build a vector of
int
s, not ofint*
s.Just skip the NULL, as that is default for pointers anyway, or cast it to the correct pointer type
(int*)NULL
.If you have the relevant C++11 support, you could use
nullptr
:However, in your particular case, there is no need to specify a default value, so the following would suffice: