zmoelnig@iem.at wrote:
Quoting "Mathieu Bouchard" matju@artengine.ca:
hi, the problem is not the type of «filename», it's the type of «extension», because the error message is about casting const to non-const, and not the other way around.
True - nicely spotted.
"man strrchr" says: char *strrchr(const char *s, int c);
Sure, but that's the C version, I imagine?
"two overloaded versions provided in C++." -- http://www.cplusplus.com/reference/clibrary/cstring/strrchr/
i don't see any problems here. what is it, that i am missing?
C != C++
C++ should use only the argument types to determine which function to call (if my memory is correct).
So a const argument forces C++ strrchr to return a const result (which is semantically correct, imho the C version is incorrectly specified to the point of being dangerous).
This cannot be converted to a non-const value without explicit casting (and arguably shouldn't be casted at all, as const values could well be in read-only memory, causing crashes when modification is attempted).