geekbrains_oop_cpp/lesson_7/Date.hpp

77 lines
1.1 KiB
C++

#ifndef DATE_HPP_
#define DATE_HPP_
#include <iostream>
class Date
{
private:
int m_day;
int m_month;
int m_year;
public:
Date(int day, int month, int year) : m_day(day), m_month(month), m_year(year) {}
const int& getDay() const
{
return m_day;
}
const int& getMonth() const
{
return m_month;
}
const int& getYear() const
{
return m_year;
}
friend std::ostream& operator<<(std::ostream& os, const Date& d)
{
os << d.m_day << '.' << d.m_month << '.' << d.m_year;
return os;
}
};
template <class T>
class _ptr
{
private:
T* m_ptr;
public:
_ptr(T* ptr = nullptr) : m_ptr(ptr) {}
~_ptr() { delete m_ptr; }
_ptr(_ptr& p)
{
m_ptr = p.m_ptr;
p.m_ptr = nullptr;
}
_ptr& operator=(_ptr& p)
{
if (&p == this)
return *this;
delete m_ptr;
m_ptr = p.m_ptr;
p.m_ptr = nullptr;
return *this;
}
T& operator*() const { return *m_ptr; }
T* operator->() const { return m_ptr; }
bool isNull() const { return m_ptr == nullptr; }
};
const _ptr<Date>& compares_dates(const _ptr<Date>&, const _ptr<Date>&);
void exercise_1();
void exercise_2();
#endif