Untitled
unknown
plain_text
3 years ago
1.7 kB
9
Indexable
#pragma once
#include "identity_document.h"
#include <iostream>
#include <string>
#include <ctime>
using namespace std::string_view_literals;
class Passport {
public:
operator IdentityDocument()
{
return IdentityDocument();
}
Passport()
: expiration_date_(GetExpirationDate())
{
vtable = new IdentityDocument();
this->del = &Passport::Delete;
this->vMethod = &Passport::PrintID;
std::cout << "Passport::Ctor()"sv << std::endl;
}
Passport(const Passport& other)
: expiration_date_(other.expiration_date_)
{
IdentityDocument a(*other.vtable);
std::cout << "Passport::CCtor()"sv << std::endl;
}
~Passport()
{
std::cout << "Passport::Dtor()"sv << std::endl;
delete vtable;
}
void PrintID() const
{
std::cout << "Passport::PrintID() : "sv << vtable->GetID();
std::cout << " expiration date : "sv << expiration_date_.tm_mday << "/"sv << expiration_date_.tm_mon << "/"sv
<< expiration_date_.tm_year + 1900 << std::endl;
}
void PrintVisa(const std::string& country) const
{
std::cout << "Passport::PrintVisa("sv << country << ") : "sv << vtable->GetID() << std::endl;
}
void Delete()
{
delete this;
}
void PrintUniqueIDCount()
{
vtable->PrintUniqueIDCount();
}
private:
void (Passport::*del)();
void (Passport::*vMethod)()const;
IdentityDocument* vtable;
const struct tm expiration_date_;
tm GetExpirationDate()
{
time_t t = time(nullptr);
tm exp_date = *localtime(&t);
exp_date.tm_year += 10;
mktime(&exp_date);
return exp_date;
}
};
Editor is loading...