C++ 如何使操作员过载<&书信电报;当我有两个对象时??(有关系)

C++ 如何使操作员过载<&书信电报;当我有两个对象时??(有关系),c++,overloading,operator-keyword,ostream,C++,Overloading,Operator Keyword,Ostream,我想另外显示对象的年龄,但我不知道如何在函数ostream中调用对象日期,因为它只需要两个参数。有什么建议吗?? 我是否需要创建虚拟运营商并继承日期 #ifndef HEARTRATE_H #define HEARTRATE_H #include <string> #include <iostream> #include "Date.h" using std::string; using std::cout; using std::endl; class HeartR

我想另外显示对象的年龄,但我不知道如何在函数ostream中调用对象日期,因为它只需要两个参数。有什么建议吗?? 我是否需要创建虚拟运营商并继承日期

#ifndef HEARTRATE_H
#define HEARTRATE_H
#include <string>
#include <iostream>
#include "Date.h"

using std::string;
using std::cout;
using std::endl;

class HeartRate
{
public:
    HeartRate(string fn,string ln,Date d);
    string getfname();
    string getlname();
    Date getAge(Date& d);
    inline void printH(){
        cout<<Fname<<Lname<<date.getday()<<"/"<<date.getmonth()<<"/"<<date.getyear()<<"/"<<endl;
    }
    friend std::ostream&  operator<<(std::ostream& os,const HeartRate& hr){
        os<<"First name: "<<hr.Fname<<endl;
        os<<"Last name: "<<hr.Lname<<endl;
//I want to additional display the age of the object.
        os<<"The Date of birth is: "<<        
        return os;
    }
protected:
    string Fname;
    string Lname;
    Date date;
};

class Date
{
public:
    Date(int d,int m,int y);
    int getday(){return day;}
    int getmonth(){return month;}
    int getyear(){return year;}
    inline void print(){
        cout<<day<<"/"<<month<<"/"<<year;
    }
protected:
    int day;
    int month;
    int year;
};


#endif
#如果没有心率#
#定义心率
#包括
#包括
#包括“Date.h”
使用std::string;
使用std::cout;
使用std::endl;
班心率
{
公众:
心率(字符串fn、字符串ln、日期d);
字符串getfname();
字符串getlname();
日期获取(日期和日期);
内联void printH(){

cout您还必须为类
Date
重载插入运算符,才能将其用于该类的对象:

class Date
{
      public:
          friend ostream& operator << (ostream& out, const Date& theDate){
            out << theDate.day << " / " << theDate.month << " / " 
            << theDate.year;
              return out;
          }
      protected:
           int day;
           int month;
          int year;
  };
friend std::ostream&  operator<<(std::ostream& os,const HeartRate& hr){
    os<<"First name: "<<hr.Fname<<endl;
    os<<"Last name: "<<hr.Lname<<endl;
    //I want to additional display the age of the object.
    os << "The Date of birth is: "<<  hr.date;      
    return os;
}