注册 登录
编程论坛 C++教室

对象指针出现的问题

qq68677589 发布于 2020-05-09 08:41, 1356 次点击
#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;
}
只有本站会员才能查看附件,请 登录

为什么会出现这种情况呢?求解!
1 回复
#2
rjsp2020-05-09 09:30
这种错误,完全与编程无关,你应该去配个眼镜。

既然编译器说 Student 没定义,那你就应该去你定义它的地方检查一下,看看 Sstudent 和 Student 有什么不同。
1