Untitled
unknown
plain_text
2 years ago
1.7 kB
3
Indexable
Never
#pragma once #include <iostream> #include <string> using namespace std::string_view_literals; class IdentityDocument { public: void (IdentityDocument::*vMethod)()const; void (IdentityDocument::*vdel)(); IdentityDocument() : unique_id_(++unique_id_count_) { this->vMethod = (void (IdentityDocument::*)()const)&IdentityDocument::ID; this->vdel = (void (IdentityDocument::*)())&IdentityDocument::Del; std::cout << "IdentityDocument::Ctor() : "sv << unique_id_ << std::endl; } ~IdentityDocument() { --unique_id_count_; std::cout << "IdentityDocument::Dtor() : "sv << unique_id_ << std::endl; } IdentityDocument(const IdentityDocument& other) : unique_id_(++unique_id_count_) { this->vMethod = (void (IdentityDocument::*)()const)&IdentityDocument::ID; this->vdel = (void (IdentityDocument::*)())&IdentityDocument::Del; std::cout << "IdentityDocument::CCtor() : "sv << unique_id_ << std::endl; } IdentityDocument& operator=(const IdentityDocument&) = delete; void PrintID() const { std::cout << "base print" << std::endl; (this->*vMethod)(); } static void PrintUniqueIDCount() { std::cout << "unique_id_count_ : "sv << unique_id_count_ << std::endl; } int GetID() const { return unique_id_; } void Delete() { (this->*vdel)(); } private: void Del() { delete this; } void ID() const { std::cout << "IdentityDocument::PrintID() : "sv << unique_id_ << std::endl; } static int unique_id_count_; int unique_id_; }; int IdentityDocument::unique_id_count_ = 0;