Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
2.0 kB
1
Indexable
Never
#pragma once

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

using namespace std::string_view_literals;

class DrivingLicence {
public:
    operator IdentityDocument() 
    {
        std::cout << "convert complete" << std::endl;
        return IdentityDocument();
    }
    void (DrivingLicence::*dMethod)()const;
    void (DrivingLicence::*ddel)();
    DrivingLicence() {
        this->dMethod = (void (DrivingLicence::*)()const)&DrivingLicence::ID;
        this->ddel = (void (DrivingLicence::*)())&DrivingLicence::Del;
        ((IdentityDocument*)this)->vMethod = (void (IdentityDocument::*)()const)&DrivingLicence::PrintID;
        ((IdentityDocument*)this)->vdel = (void (IdentityDocument::*)())&DrivingLicence::Delete;
        std::cout << "DrivingLicence::Ctor()"sv << std::endl;
        (this->*dMethod)();
    }

    DrivingLicence(const DrivingLicence& other)
    {
        IdentityDocument id(reinterpret_cast<const IdentityDocument&>(other));
        this->dMethod = (void (DrivingLicence::*)()const)&DrivingLicence::ID;
        this->ddel = (void (DrivingLicence::*)())&DrivingLicence::Del;
        ((IdentityDocument*)this)->vMethod = (void (IdentityDocument::*)()const)&DrivingLicence::PrintID;
        ((IdentityDocument*)this)->vdel = (void (IdentityDocument::*)())&DrivingLicence::Delete;
        std::cout << "DrivingLicence::CCtor()"sv << std::endl;
    }

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

    void PrintID() const {
        //std::cout << "befor" << std::endl;
        (this->*dMethod)();
        //ID();
        //std::cout << "after" << std::endl;
    }
    
    void Delete()
    {
         (this->*ddel)();
    }
    private:
    static int unique_id_;
    void ID() const {
        std::cout << "DrivingLicence::PrintID() : "sv << ((IdentityDocument*)this)->GetID() << std::endl;
    }
    
    void Del()
    {
        delete this;
    }
};
int DrivingLicence::unique_id_ = 0;