C++|取消引用成员指针



好吧,假设我有一个structclass,它的成员之一是int指针,类似于以下内容:

struct /*or class*/ some_struct /*or class*/ {
int *pointer = NULL;
} *obj_pointer;

随着程序的进行,obj_pointerobj_pointer->pointer被初始化,我如何取消引用obj_pointer->pointer,以便打印(cout(,例如指针指向的内存值?

就像任何其他指针一样,使用解引用运算符*:

std::cout << *obj_pointer->pointer;

成员访问运算符->具有比解引用运算符*更高的运算符优先级

最新更新