how to fill array of pointers with NULL?
arrays, c++
Solution
The error message is kind of clear, if you understand what `NULL` really is: a literal `0`.
When you pass `0` to a template, the deduced type is `int`, not a pointer type. While a literal `0` is implicitly convertible to any pointer type and will be a null pointer, after it if passed to `fill` it is just an `int` with value 0, which is not convertible to a pointer type.
In C++11 you could and should use `nullptr` instead of `NULL`. In C++03 you can also convert the pointer to the destination type:
std::fill(orders, orders + Size, static_cast<LimitOrder*>(0));
But then again, why go through the process in the first place when you can zero-initialize the array in the initializer list?
InternalIdAssigner::InternalIdAssigner()
: lastCleanId(), orders() {}
Problem
I have array of pointers: ``` private: LimitOrder* orders[Size]; ``` In constructor i'm trying to fill it with NULL: ``` InternalIdAssigner::InternalIdAssigner(void): lastCleanId(0) { std::fill(orders, orders + Size, NULL); ``` But this doesn't work, I receive error: `error C2440: '=' : cannot convert from 'const int' to 'LimitOrder *'` What is the right way to fill array field with NULL?