这个问题已经在这里有了答案:
7年前关闭。
当我碰到这一行代码时,我正在阅读FLTK代码:
Fl_Widget*const* a = array();
这是实际的代码:
Fl_Widget*const* Fl_Group::array() const {
return children_ <= 1 ? (Fl_Widget**)(&array_) : array_;
}
int Fl_Group::find(const Fl_Widget* o) const {
Fl_Widget*const* a = array();
int i; for (i=0; i < children_; i++) if (*a++ == o) break;
return i;
}
现在我想知道指针变量
a
的类型是什么。 Fl_Widget*const* a = array();
和Fl_Widget** const a = array();
是否相等? 最佳答案
您从右到左阅读:
Fl_Widget * const * a
"pointer to" <- "constant" <- "pointer to" <- "a is"
总计为“
a
是指向Fl_Widget
的常量指针的指针”。VAR a: POINTER TO CONST POINTER TO Fl_Widget
样式的声明会更清楚一些,但是C++将变量声明语法从C中拖了出来,而C都是关于表达式的,而不是数据类型的。哎呀,它甚至没有const
字,所以您不必考虑它,并且int *a, b
显然被解读为“*a
是int
,而b
是int
”。关于c++ - “int* const* num”是什么意思? ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14052633/