C/C++中“->”使用注意事项
“->”运算符叫做“指向结构体成员运算符”,是C语言和C++语言的一个运算符。使用时应注意符号左边应该为指针。
#include<iostream>
using namespace std;
struct person {
int *age = new int(10);
};
int mian()
{
person p;
cout << *p.age << endl;
system("pause");
return 0;
}
这里*p.age中p.age是一个指针,因此写成p->age程序会报错。