- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
#define TYPE_INIT_(_Number, _Line, _Type,...) struct ln_##_Line##_number_##_Number : public _Type\
{\
ln_##_Line##_number_##_Number()\
:_Type(__VA_ARGS__){}\
\
ln_##_Line##_number_##_Number(const _Type& _val)\
:_Type(_val){}\
\
const _Type& operator=(const _Type& _val)\
{\
((_Type)(*this)) = _val;\
return (*this);\
}\
}
#define TYPE_INIT(_Number, _Line, _Type,...) TYPE_INIT_(_Number, _Line, _Type, __VA_ARGS__)
#define INIT(_Type, ...) TYPE_INIT(__COUNTER__, __LINE__, _Type, __VA_ARGS__)
// использование
struct ABC
{
int A,B,C;
ABC(int _A,int _B,int _C)
:A(_A),
B(_B),
C(_C)
{}
};
struct TestClass
{
INIT( string, "Ololo" ) lv_String;
INIT( ABC, 1, 2, 3 ) lv_ABC;
};