我正在努力理解这个常量和指针。
typedef cu::Op const * operation_t;
typedef operation_t const * const_operation_ptr_t;
operation_t
是指向const cu::Op
对象的指针吗?
在第二行中,如果用operation_t
代替,则得到cu::Op const * const *
。
这是否意味着const_operation_ptr_t
是一个常量指针(其地址不能更改(,它指向一个值不能更改的常量对象?
typedef名称operation_t
表示指向cu::Op
类型常量对象的非常量指针。
typedef cu::Op const * operation_t;
typedef名称const_operation_ptr_t
表示指向类型cu::Op const *
的常量指针的非常量指针。
typedef operation_t const * const_operation_ptr_t;
要使两种引入的指针类型都成为常量指针类型,您需要编写
typedef cu::Op const * const operation_t;
和
typedef operation_t const * const const_operation_ptr_t;
一个更简单的例子。这两个声明
const int *p;
和
int const *p;
等效,并声明指向类型为CCD_ 10的对象的非常量指针。
此申报
int * const p = &x;
声明一个指向int类型的非常量对象的常量指针。
这些声明
const int * const p = &x;
和
int const * const p = &x;
是等效的,并声明一个指向const int类型的常量对象的常量指针。