Тема: Помилка в коді
Доброго вечора, допожіть будь-ласка вирішити помилку.
Помилка у 26 строчці main.cpp C2662 int Date::getDay(void): неможливо перетворити покажчик "this" з"const NoteBook" у "Date &"
Код date.h
class Date {
private:
int day;
int month;
int year;
public:
Date() {
this->day = 0;
this->month = 0;
this->year = 0;
}
Date(int day, int month, int year) {
this->day = day;
this->month = month;
this->year = year;
}
Date( const Date& date) {
this->day = date.day;
this->month = date.month;
this->year = date.year;
}
void setDay(int day) {
this->day = day;
}
void setMonth(int month) {
this->month = month;
}
void setYear(int year) {
this->year = year;
}
int getDay() {
return day;
}
int getMonth() {
return month;
}
int getYear() {
return year;
}
virtual void show() {
std::cout << "Date: " << this->getDay() << ":" << this->getMonth() << ":" << this->getYear() << "\n";
std::cout << std::endl;
}
virtual void input() {
std::cout << "Enter day: ";
std::cin >> this->day;
std::cout << "Enter month: ";
std::cin >> this->month;
std::cout << "Enter year: ";
std::cin >> this->year;
}
};
Код main.cpp
#include <iostream>
#pragma once
#include "Header.h"
#include "Date.h"
#define YEAR 365
#define MONTH 31
class NoteBook : public Date {
private:
std::string name;
std::string phoneNumber;
public:
NoteBook() : Date() {
this->name = "";
this->phoneNumber = "";
}
NoteBook(std::string name, std::string phoneNumber, int day, int month, int year) : Date(day, month, year) {
this->name = name;
this->phoneNumber = phoneNumber;
}
NoteBook(const NoteBook& noteBook) : Date(Date(noteBook.getDay(), noteBook.getMonth(), noteBook.getYear())) { //помилка
this->name = noteBook.name;
this->phoneNumber = noteBook.phoneNumber;
//Date(Date(noteBook.getDay(), noteBook.getMonth(), noteBook.getYear()));
}
void setName(std::string name) {
this->name = name;
}
void setPhoneNumber(std::string phoneNumber) {
this->phoneNumber = phoneNumber;
}
std::string getName() {
return this->name;
}
std::string getPhoneNumber() {
return this->phoneNumber;
}
void show() {
std::cout << std::endl;
std::cout << "Name: " << this->getName() << std::endl;
std::cout << "Phone number: " << this->getPhoneNumber() << std::endl;
Date::show();
}
void input() {
std::cout << "Enter name: ";
std::cin >> name;
std::cout << "Enter phone number: ";
std::cin >> phoneNumber;
Date::input();
}
int getDaysBeforeBirthDay() {
Date* date = new Date();
std::cout << "Enter current date:" << std::endl;
date->input();
int dayBefore;
int monthBefore;
int yearBefore;
yearBefore = abs(this->getYear() - date->getYear()) * YEAR;
monthBefore = abs(this->getMonth() - date->getMonth()) * MONTH;
dayBefore = abs(this->getDay() - date->getDay()) + monthBefore;
std::cout << "Days before birthday: " << dayBefore << std::endl;
delete date;
return dayBefore;
}
};
int main() {
NoteBook notebook;
notebook.input();
notebook.show();
}