Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
1.1 kB
5
Indexable
Never
#pragma once

#include "identity_document.h"
#include <iostream>
#include <string>

using namespace std::string_view_literals;

class DrivingLicence {
public:
	operator IdentityDocument()
	{
		return IdentityDocument();
	}

    DrivingLicence() 
	{
		this->vMethod = &DrivingLicence::Id;
		this->del = &DrivingLicence::Del;
		vtable = new IdentityDocument();
		std::cout << "DrivingLicence::Ctor()"sv << std::endl;
    }

    DrivingLicence(const DrivingLicence& other)
    {
        IdentityDocument a(*other.vtable);
        std::cout << "DrivingLicence::CCtor()"sv << std::endl;
    }

    ~DrivingLicence() {
        std::cout << "DrivingLicence::Dtor()"sv << std::endl;
		delete vtable;
    }

    void PrintID() const 
	{
        (this->*vMethod)();
    }

	void Delete()
	{
		(this->*del)();
	}
private:
	void (DrivingLicence::*del)();
	void (DrivingLicence::*vMethod)()const;
	IdentityDocument* vtable;

	void Id() const
	{
		std::cout << "DrivingLicence::PrintID() : "sv << vtable->GetID() << std::endl;
	}

	void Del()
	{
		delete this;
	}
};