impl.h

来自「开放源码的编译器open watcom 1.6.0版的源代码」· C头文件 代码 · 共 54 行

H
54
字号
//
// Class definitions provided by a library vendor.
//

#include <string>

class employee {
    std::string Name;
protected:
    int     hourRate;
public:
    employee( const char *n, int hr );
    virtual ~employee();

    std::string name() { return( Name ); }
    virtual int salary() = 0;
};

class manager : public employee {
    int     Experience;
public:
    manager( const char *n, int hr, int ex ) :
        employee( n, hr ), Experience( ex ) {}
    int salary();
};

//
// The following is a 'programmer' class defined by the user and based on
// the 'employee' class. Data members Overtime and OvertimeRate, and the
// member functions setOvertimeRate, addOvertime, resetOvertime and
// overtimePay were added.
//
// In a situation where library vendor didn't provide the source code for
// impl.cpp, users cannot recompile that module and hence cannot add any
// virtual member functions to the 'employee' base class. This means that
// in a heterogeneous collection of employees one needs to first check if
// an employee is a programmer before attempting to invoke one of the
// additional member functions.
//

class programmer : public employee {
    int     OvertimeRate;
    int     Overtime;
public:
    programmer( const char *n, int hr ) : employee( n, hr ) {}
    void setOvertimeRate( int otr ) { Overtime = 0; OvertimeRate = otr; }

    void addOvertime( int ov ) { Overtime += ov; }
    void resetOvertime() { Overtime = 0; }
    int  overtimePay() { return( Overtime * OvertimeRate ); }

    int  salary() ;
};

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?