小编Lun*_*nch的帖子

友元函数+运算符重载

我正在研究一个类似于工资单的项目.部分提示说

"您可以定义一个重载<<的函数函数,用于显示Employee对象信息(即重载<<函数将调用虚拟打印函数.)"

我知道朋友的功能是什么,但我不记得了解过载<<部分.我试着寻找一些简单的复制粘贴实现...但无论我尝试什么,我的编译器都会突然爆​​发.

我该如何实际实现这个?这是我到目前为止的代码:

#include <iostream>
#include <string>

using namespace std;

//Base class
class Employee
{
public:
    Employee(string a, string b, string c, string d);
    ~Employee();
    int virtual earnings();
    void virtual print();
protected:
    string first, last, brithday, department;
};

Employee::Employee(string f, string l, string b, string d)
{
    first = f;
    last = l;
    brithday = b;
    department = d; //department code
    cout << "Employee created." << endl;
}

Employee::~Employee(void)
{
    cout << "Employee deleted." << endl;
}

int Employee::earnings() …
Run Code Online (Sandbox Code Playgroud)

c++ operator-overloading friend

0
推荐指数
1
解决办法
9748
查看次数

标签 统计

c++ ×1

friend ×1

operator-overloading ×1