I have this array
unsigned char bit_table_[10][100];
What is the right way to fill it with 0. I tried
std::fill_n(bit_table_,sizeof(bit_table_),0x00);
but vc 2010 flags it as error.
I have this array
unsigned char bit_table_[10][100];
What is the right way to fill it with 0. I tried
std::fill_n(bit_table_,sizeof(bit_table_),0x00);
but vc 2010 flags it as error.
On initialization:
unsigned char bit_table_[10][100] = {};
If it's a class member, you can initialize it in the constructor, like this:
MyClass::MyClass()
:bit_table_()
{}
Otherwise:
std::fill_n(*bit_table_,sizeof(bit_table_),0);
The type of bit_table_
is unsigned char [10][100]
, which will decay (that is, the compiler allows it to be implicitly converted to) into unsigned char (*)[100]
, that is, a pointer to an array of 100 unsigned chars
.
std::fill_n(bit_table_, ...)
is then instantiated as:
std::fill_n(unsigned char (*)[100], ...)
which means it expects a value of type unsigned char [100]
to initialize bit_table_
with. 0
is not convertible to that type, so the compilation fails.
Another way to think about it is that the STL functions that deal with iterators only deal with a single dimension. If you are passing in a multidimensional structure those STL functions will only deal with a single dimension.
Ultimately, you can't do this; there is no way to assign to an array type. I.e., since you can't do this:
char table[100];
char another_table[100]= { };
table= another_table;
you can't use std::fill_n
on multidimensional arrays.
You can also try unsigned char bit_table_[10][100]= { 0 }
to fill it with zeros.
int main()
{
unsigned char bit_table_[10][100]= { 0 };
return 0;
}