* problem
* need to explain the problem
* need to understand the problem to explain it
* ...
* never mind
Oh, well. Since the problem i had was a simple one (the facepalm moment arrived in the middle of writing the very first sentence for me) - i post it anyway for readers benefit as i have encountered variations of this problem fairly often.
------------
Why cannot "Foo *" be implicitly converted to "Foo const *&"?
silly-made-up-simplified-mini-example:
void skipX(char const *&at) {
if(*at == 'X') at++;
}
void snafu() {
char *buf = ...
skipX(buf); // not OK! -> 'Conversion loses qualifiers' !
...
}
Noticed the problem? Did you think about it? Did thinking about it help? ------------
Oh, well - my take on the pesky WHY:
Foo const constFoo;
Foo *ptrFoo;
Foo const **snafu = &ptrFoo; // *** ie. if it WOULD allow this then the following can legally happen ***
*snafu = &constFoo; // exact type match: both sides are "Foo const *"
*ptrFoo = @#$%! // completely valid to do whatever with the Foo ... ow, crap - it just happens to be constFoo.
Aliasing issue, lovely. Compiler errs on the side of caution (validity of the code is the goal, not some version of const correctness in and of itself ... but that is a rant for another time deep in the complicated waters of language design not relevant to C++ with its constraints of history).... and this kind of mind-wrappers are why one generally tries to avoid low level C++.
C++, the sledgehammer of const correctness.
------------
So, what C++ thread did you not make lately?