c++ 使用对象指针

#include <iostream>
using namespace std;

class Student{
public:
    char name;
    int age;
    float score;

    void say(){
        cout<<name<<"的年龄是"<<age<<",成绩是"<<score<<endl;
    }
};

int main(){
    Student *pStu = new Student;
    pStu -> name = "小明";
    pStu -> age = 15;
    pStu -> score = 92.5f;
    pStu -> say();
    delete pStu;  //删除对象

    return 0;
}

posted @ 2022-08-19 22:52  luoganttcc  阅读(9)  评论(0)    收藏  举报