You can use a CRT template to share typename, you just need to specify it in the inheritance list.
template<class T> struct Type { using type = T; }; struct ThisScruct : Type<ThisStruct> { int a; double b;
You can rename Type to a more friendly name. But you can consider completely replacing this functionality with a CRT template by moving functions to an inherited structure.
template<class T> struct SumOffsets { static size_t sum_offsets(){ typedef T SelfT; return offsetof(SelfT, a) + offsetof(SelfT, b); } }; struct ThisStruct : SumOffsets<ThisStruct> { int a; double b; };
The sum_offsets function can be accessed through ThisStruct::sum_offsets , because even static functions are inherited. SumOffsets does not SumOffsets any additional costs, since neither virtual functions are involved nor SumOffsets have data members.
cmdLP source share