#pragma once#include iostream#include stringclass Personpublic virtual ~Person ; void setNameconst stdstring &name; stdstring name const; virtual void showInfo = 0;protected stdstring m_name;;详细解释每行用中
#pragma once // 预处理指令,确保头文件只被编译一次
#include
#include
class Person // 定义一个名为Person的类 { public: // 公有访问权限 virtual ~Person() {}; // 虚析构函数,用于释放派生类对象时调用 void setName(const std::string &name); // 成员函数,设置姓名 std::string name() const; // 成员函数,获取姓名 virtual void showInfo() = 0; // 纯虚函数,用于输出个人信息 protected: // 受保护的访问权限 std::string m_name; // 成员变量,保存姓名 }; // 类定义结束
原文地址: https://www.cveoy.top/t/topic/iSTA 著作权归作者所有。请勿转载和采集!