See some articles, do a VC, CB, GCC General Property Declaration macro function, by CB and Devcpp test pass, release version of efficiency without loss. I don't know what the C + + committee is eating, doing that standard library all day, but refusing to expand the basic functionality. Object-oriented class three operations: Methods, properties, events, where properties will not provide the editor support standards, CB and VC many years ago to support, not C + + can not do, just in the programming process, those get () and set () The Operation function is not beautiful, writing also laborious, the whole look up, There are too many brackets ()!
The code is as follows:
Property
#if defined (__borlandc__) | | defined (_MSC_VER)
#define PROPERTY_GET_SET (class, type, name, getter, setter) \
__declspec (property (Get=getter, Put=setter)) type name;
#define PROPERTY_GET (class, type, name, getter) \
__declspec (property (get=getter)) type name;
#define Property_begin
#define Property_end
#else//defined (__borlandc__) | | defined (_MSC_VER)
//The property of the simulation is occupied by Space
#define Property_get_set (class_t, type_t, name, getter, setter) \
class property_# #name \
{\
Public:\
Friend class Class_t;\
Inline size_t offset () {return offsetof (class_t, name);} \
inline class_t* parent () {return reinterpret_cast<class_t*> (size_t (This)-offset ());} \
template<typename t> inline operator T () \
{\
return T (parent ()->getter ()); \
}\
inline property_# #name & operator= (const type_t& n) \
{\
parent ()->setter (n);
return *this;\
}\
}name;
#define Property_get (class_t, type_t, name, getter) \
class property_# #name \
{\
Public:\
Friend class Class_t;\
Inline size_t offset () {return offsetof (class_t, name);} \
inline class_t* parent () {return reinterpret_cast<class_t*> (size_t (This)-offset ());} \
template<typename t>inline operator T () \
{\
return T (parent ()->getter ()); \
}\
private:\
property_# #name & operator= (const type_t& n); \
}name;
//Put property in a union, can effectively reduce the occupation of class space
#define Property_begin union{
#define Property_end};
#endif//defined (__borlandc__) | | defined (_MSC_VER)
Then talk about using C + + to implement property, do not understand what those committees are eating.