疑惑1:在类中,有参构造函数传入参数时,取地址符的效果
class Person
{
public:
Person(int s, int a) {
cout << "有参构造函数" << endl;
sex = &s;
age = &a;
cout << *age <<" "<< *sex << endl;
}
~Person() {
cout << "析构函数" << endl;
}
int* sex;
int* age;
};
为什么输出时只能先输出p1.sex才能看到正确的值,且仅能看到p1.sex的值!