There is nothing we can do There is nothing we can do - 3 months ago 27
C++ Question

Conversion loses qualifiers, but doesn't really

This is somewhat related, but also bit different to: C++ "conversion loses qualifiers" compile error

In my code I'm getting following error:


error C2440: 'initializing': cannot convert from 'const git_commit
*const *' to 'const git_commit **'


As much as I understand that assigning from T** to const T** would allow to violate rules of constness, here in the example I gave, that is, assigning from const T*const * to const T** actually gains constness, without loosing any, so where/why this is a problem?

Answer
const git_commit * const *

a pointer to a constant array of pointers to constant git_commits

const git_commit * *

a pointer to a mutable array of pointers to constant git_commits

assigning a const array to a mutable array loses const.