好吧,假设我有一个struct
或class
,它的成员之一是int
指针,类似于以下内容:
struct /*or class*/ some_struct /*or class*/ {
int *pointer = NULL;
} *obj_pointer;
随着程序的进行,obj_pointer
和obj_pointer->pointer
被初始化,我如何取消引用obj_pointer->pointer
,以便打印(cout
(,例如指针指向的内存值?
就像任何其他指针一样,使用解引用运算符*
:
std::cout << *obj_pointer->pointer;
成员访问运算符->
具有比解引用运算符*
更高的运算符优先级