对象指针出现的问题
#include<iostream>#include<cstdlib>
#include<string>
using namespace std;
class Sstudent
{
public:
//创建数据成员
const char* name;
int number;
int age;
float score;
//创建成员函数
void print()
{
cout << name << endl;
cout << number << endl;
cout << age << endl;
cout << score << endl;
}
};
int main()
{
//创建对象
Student *pStu = new Student;
pStu->name = "小明";
pStu->number = 6019203034;
pStu->age = 22;
pStu->score = 66.4;
pStu->print();
delete pStu;
return 0;
}
为什么会出现这种情况呢?求解!