C++实现类设计一个类,包含构造函数、析构函数等?

2024-12-04 12:53:25
推荐回答(2个)
回答1:

        //CStudent.h
calss CStudent
{
    public:
        long ID;
        char* pchName;  
        float fWeight;
    
    public:
        CStudent();//构造
        ~CStudent(); //析构
};
 
// CStudent.cpp
#include "iostream"

CStudent();
{
    ID = 0;
    pchName = NULL;
    fWeight = 0.0f; 
}   

~CStudent(){}; //析构

int main()
{    
    CStudent stu;
    stu.ID = 123;
    stu.pchName = "GG";
    stu.fWeight = 55.0f;  
 
    std::cout     
        <<"id:"<        <<"name:"<        <<" weight"< 
    return 0; 
}

回答2:

C++实现类设计我会提前帮你准备.