I’m using the type aliases for pointer
and const pointer
and I don’t understand why there is difference between returning a cost pointer
and a const_pointer
.
I assumed that const pointer
, in this case, is equivalent to const int*
, but I’m getting an invalid conversion compile error:
error: invalid conversion from 'const int*' to 'S::pointer {aka int*}
struct S
{
using pointer = int*;
using const_pointer = const int*;
// const_pointer get() const { return &i; } // OK
const pointer get() const { return &i; } // ERROR
int i = {};
};
int main()
{
const S s;
s.get();
}
1