📄 employee.h
字号:
// Header file for the Employee class, the base class for// maintaining employee records#ifndef CLASS_Employee#define CLASS_Employee#include <string>#include <iostream>#include <sstream>class Employee {public: // Constructors Employee(); Employee( const std::string& name, const std::string& SSN ); // Copy constructor Employee( const Employee& e ); // By declaring the destructor virtual, we ensure that // if we delete a pointer to an Employee object, but // the object belongs to a derived class, the destructor // for the derived class will be called as well virtual ~Employee(); // Get/Set pairs to work with member variables inline std::string GetName() const { return m_Name; } inline void SetName( const std::string& name ) { m_Name = name; } inline std::string GetSSN() const { return m_SSN; } inline void SetSSN( const std::string& ssn ) { m_SSN = ssn; } // The = 0 makes this function pure virtual, and // makes this entire class an abstract base class, // so you cannot create an Employee object! You // must create an instance of a derived class virtual double GetYearlyPay() const = 0; // Making these functions virutal ensures that the // proper SendTo/GetFrom function will be called, // depending on the kind of employee this object // actually is virtual void SendTo( std::ostream& out ) const; virtual void GetFrom( std::istream& in, bool prompt = false ); protected: // These members are available to derived classes, // but not to outside code std::string m_Name; std::string m_SSN; private: // Checks whether SSN has valid format bool IsValidSSN() const; // This is used by IsValidSSN() to check any of the // three numeric portions of the SSN. It does not // use any data members, so we declare it static static bool GetSSNPart( std::istringstream& is, int maxval ); // This is an entity type, so we don't want the // compiler implementing a public assignment operator! // Defining a private assignment operator prevents this Employee& operator=( const Employee& e ); } ;// Input/output operators work with any kind of employeestd::ostream& operator<<( std::ostream& out, const Employee& e );std::istream& operator>>( std::istream& in, Employee& e );#endif // CLASS_Employee
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -