I have a static array of integers that I never want to change. I have a C-style function that wants to have this array as a void-pointer parameter. I am trying out different combinations of const_cast and reinterpret_cast, but I'm coming to the point where I have no clue of what I'm exactly doing and it keeps giving me errors.
class Foo
{
static constexpr int bar[3] = {1,2,3};
void method()
{
cfunction(reinterpret_cast<void*>(const_cast<int*>(&bar)));
}
};
invalid const_cast from type 'const int ()[3]' to type 'int'
I see that it fails because the types don't match. I also tried const_cast<int[]>(bar)
, but const_cast
wants to have a pointer or reference type.
Where can I read up on this subject? It's hard for me to understand what is going on here.