Variant (variant)
Variant types can theoretically store any type of data, which is why many people in Chinese call it "variants." It is strange for a programmer with a strongly typed language such as C + + to have a Variant (variant) of that type. However, for those languages that dilute the concept of the type, such as Visual Basic, the variant is their default type. In VB, if the variable is not declared with the AS statement, then the variable is variant type. For C + + programmers, the variant is simply a complex structure:
typedef/* [Wire_marshal]/struct tagvariant VARIANT;
struct tagVARIANT
{
Union
{
struct __tagvariant
{
VARTYPE VT;
WORD wReserved1;
WORD WReserved2;
WORD wReserved3;
Union
{
Longlong Llval;
LONG lval;
BYTE Bval;
Short ival;
FLOAT Fltval;
DOUBLE dblval;
Variant_bool Boolval;
_variant_bool BOOL;
SCODE SCODE;
CY Cyval;
Date date;
BSTR Bstrval;
IUnknown *punkval;
IDispatch *pdispval;
SAFEARRAY *parray;
BYTE *pbval;
Short *pival;
LONG *plval;
Longlong *pllval;
FLOAT *pfltval;
DOUBLE *pdblval;
Variant_bool *pboolval;
_variant_bool *pbool;
SCODE *pscode;
CY *pcyval;
DATE *pdate;
BSTR *pbstrval;
IUnknown **ppunkval;
IDispatch **ppdispval;
SAFEARRAY **pparray;
VARIANT *pvarval;
PVOID ByRef;
CHAR Cval;
USHORT Uival;
ULONG Ulval;
ULONGLONG Ullval;
INT intval;
UINT Uintval;
DECIMAL *pdecval;
CHAR *pcval;
USHORT *puival;
ULONG *pulval;
ULONGLONG *pullval;
INT *pintval;
UINT *puintval;
struct __tagbrecord
{
PVOID Pvrecord;
IRecordInfo *precinfo;
} __variant_name_4;
} __variant_name_3;
} __variant_name_2;
DECIMAL Decval;
} __variant_name_1;
} ;
Variant types are widely used in both interpretative and scripting languages. In the visual basic,javascript and so on body, everywhere visible its figure. But without the support of language, the variant operation is complex. Unfortunately, this is the case for C + +. This should be said to be concerned with C + + 's cautious approach to new technologies and the language that is controlled by a non-pure business company. Other languages such as Delphi, must keep pace with the times, is sure to add a variant of the built-in support.