const ptr<ubyte>
is the same as const (ubyte *)
which is not the same as const ubyte (*)
. You are trying to return a const
pointer to a non-const char
, which the compiler won't allow because you've declared the function itself const
; all members become const
because of that. The compiler won't automatically cast const to non-const without a const_cast
.
To make the difference clearer, the first is a const pointer to a non-const char
and the second is a non-const pointer to a const char
. The first allows the pointed-to characters to change, even though the pointer itself can't change. Since the function was marked as const
it can't return anything that would allow its members to be modified.
The best way to fix it:
ptr<const ubyte>
getColor1() const {
return &colors[0];
}