c++ - Will metaclasses replace inheritance? -


i've watched videos , articles on metaclasses , , imo have potential replace inheritance , providing way sort of compile-time inheritance.

with metaclasses can provide interfaces, default function implementation, , correctness of implementation(not body of functions of course) of class during compilation. there can't done in metaclasses can done inheritance, polymorphism , oo stuff?

just general remark, write "frequent" author of python metaclasses: metaclasses not meant "day day" use, , c++ metaclasses may not same in python, can hardly see such concept used replace common inheritance.

inheritance have roles. if in need special rules whole class hierarchy, may useful have metaclass specify these rules start with. (the first example in both c++ proposal , on explanatory material i've browsed "interfaces" - mandates methods virtual). so, supposing find out special rule want in whole set of classes in system , can express using metaclass, not preclude creating single base-class metaclass, , create other classes "normal" inheritance, if change 1 such class usual method overriding , specialization: inheritance still simpler, both code, whoever reads code, toolchain echo system evolved around c++ in decades of language existance.

so, yes, metaclass inheritance could, is, allow encode common capabilities of classes in metaclass, , them create new classes using metaclass, instead of inheritance. there no motives on earth that.

just bridge python, acquainted concept: language took 1 step in opposite direction - enabling 2 mechanisms in normal inheritance in version 3.6 possible through metaclasses, , in doing that, further reducing use cases metaclasses needed due complication call for.


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -