class MyClass : SomeFeatureGeneratedByTemplate<MyClass>
The template offers a lot of convenience for adding functions to our class, simply inheriting the template of the class instance.
However, sometimes this function may be too complex to implement as a template, where a macro may be the only choice.
MACRO_TO_GENERATE_COMPLICATED_FEATURE(MyClass)
/* Might be expanded to
class MyClassFeature { ... };
*/
class MyClass : MyClassFeature
I wonder if the following syntax will simplify: let you define an anonymous class in place
class MyClass : class { ... }, class{ ... }
Therefore, the above code can be rewritten as:
class MyClass : MACRO_GEN_FEATURE(MyClass)
APPEND:
Q: Why I do not embed the code only inside the class?
A: 1. This function must be explicit and accessible to the user. When they generate documents, the derived class is easy to detect: class A: FEATURE1(A), FEATURE2(A)but the inline macro does not. Although an empty pool can be obtained to achieve our goal (e.g. class A: FEATURE1(A)//just derive predefined struct FEATURE1_EMPTY{};), this is apparently not an ideal solution.
- , , (, static_assert ).
, , , 2).
, , ++?