lundi 10 août 2020

why am I getting no match for 'operator== [closed]

In my program I have an if statement that is supposed to run if I a function returns a -1 or a 0. Here is my main

/*
 * 
 * cout appointment time and duration for a given date
 * format5Col: a constant that helps pretty print in fixed # columns
*/ 

#define format5Col  setfill(' ') << std::right << std::setw(5)

#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
#include "Appointment.h"
using namespace std;
void callPrint (MeetingSchedule &TimeOrApptObject) {                                                     
     TimeOrApptObject.print();                                                           
  }   

void processNextArrayElement (Appointment myAppointmentArray[], int lowPosn, int totalNumberOfAppointments, Date myDate){
  
  int noAppointments=20;
  Time thisTime;
     

if(lowPosn !=  noAppointments){
  if ((friendToCompareDates(myDate,myAppointmentArray[lowPosn]) == -1 || (myDate,myAppointmentArray[lowPosn])==0)) {
        
    thisTime = myAppointmentArray[lowPosn]; callPrint(thisTime);
    callPrint( myAppointmentArray[lowPosn]);

    cout << endl;
}
lowPosn ++;
}
return;
}



/**
void callPrint(Time timeObject ) {
  timeObject.print();
}
*/
                              
int main() {
  int const SIZE = 40;
  Appointment myAppointmentArray[SIZE];
  
  ifstream infile;
  //int mon, dat, yr, hr, min, hl;
  int month, date, year, hour, minute, duration;
  int numberOfAppointments = 0;
  infile.open("Homework5Data.txt");
  while (infile >> month >> date >> year >> hour >> minute >> duration) {
    myAppointmentArray[numberOfAppointments] = 
         Appointment(month, date, year, hour, minute, duration);
    numberOfAppointments++;
  }
  infile.close();
 
  //get user's date and print appointment info for that date 
  cout << "Appointment date:  mm dd yyyy?  ";
  cin >> month >> date >> year;
  Date myDate (month, date, year);

  cout << "Appointment Date: " << month << " " << date << " " << year << endl;
  cout <<"     " << "hh" << "     " << "mm" << "  len" << endl; 
  void processNextArrayElement (Appointment myAppointmentArray[], int lowPosn, int totalNumberOfAppointments, Date  myDate);

}

> Here is MeetingSchedule.h
#ifndef  MEETINGSCHEDULE_H
#define MEETINGSCHEDULE_H
class MeetingSchedule   {
public:
virtual void print()=0;
};

#endif

Here is Time.h // Time.h -- Class Time UPDATE as needed

#ifndef TIME_H
#define TIME_H
#include "MeetingSchedule.h"
#include <iostream>
#include <iomanip>
using namespace std; 

class Time : public virtual  MeetingSchedule {
 private :
   int hour; int minute;
 public:
   Time () { } 
   Time (int hour, int minute) {
     this->hour = hour;
    this->minute = minute;
   }
   virtual void print() {
     cout << "     " << hour << "     " << minute;
   }
};

#endif

here is Date.h

// Date.h -- Class Date    UPDATE  as needed
#ifndef DATE_H
#define DATE_H
#include "MeetingSchedule.h"
#include <iostream>
#include <iomanip>
using namespace std; 

class Date : public virtual  MeetingSchedule  {  
  private:
    int month;
    int day;
    int year;
  public:
    Date () { } ;
    Date (int month, int day, int year) {
      this->month = month;
      this->day = day;
      this->year = year;
    }
 virtual void print() {
     cout << "    " << month << "    " << day << "    " << year;
   }


    friend int  friendToCompareDates (Date &d1, Date&d2) {
      if ((d1.month > d2.month) && (d1.day > d2.day) && (d1.year > d2.year)) 
    return -1; 
      else if  ((d1.month < d2.month) && (d1.day < d2.day) && (d1.year < d2.year))

    return 1;
else 
return 0;
    }
} ;


#endif

here is Appointment.h

#ifndef APPOINTMENT_H
#define APPOINTMENT_H
#include "Time.h"
#include "Date.h"
#include <iostream>
#include <iomanip>
using namespace std;

class Appointment: public Date, public Time  {  
 private:
  int howLong;
 public:
  Appointment (): Date(),Time() { } 
  Appointment (int month, int date, int year, 
                                        int hour, int minute, int duration):
               Date(month, date, year), Time(hour, minute) {
    howLong = duration;
  }
  virtual void print() {
    cout << "     " << howLong;
  }
};

#endif

So If firstDateLessThanEqual2ndDate equals -1 or 0 then the program inside the if statement should run but instead I am getting the error no match for 'operator==' (operand types are 'Appointment' and int. Is the format for the code I'm using off or is there something missing? Please leave an example in your answer it would be much apreaciated. Thank you for your time

Aucun commentaire:

Enregistrer un commentaire