|
1 | 1 | --- |
2 | | -description: "Learn more about: _variant_t::operator =" |
3 | | -title: "_variant_t::operator =" |
4 | | -ms.date: "11/04/2016" |
| 2 | +description: "Learn more about: _variant_t::operator=" |
| 3 | +title: "_variant_t::operator=" |
| 4 | +ms.date: 03/23/2021 |
5 | 5 | f1_keywords: ["_variant_t::operator="] |
6 | 6 | helpviewer_keywords: ["operator= [C++], variant", "operator = [C++], variant", "= operator [C++], with specific Visual C++ objects"] |
7 | | -ms.assetid: 77622723-6e49-4dec-9e0f-fa74028f1a3c |
8 | 7 | --- |
9 | | -# _variant_t::operator = |
| 8 | +# `_variant_t::operator=` |
10 | 9 |
|
11 | | -**Microsoft Specific** |
| 10 | +Assigns a new value to a `_variant_t` instance. |
| 11 | + |
| 12 | +The `_variant_t` class and its `operator=` member are **Microsoft-specific**. |
12 | 13 |
|
13 | 14 | ## Syntax |
14 | 15 |
|
| 16 | +```cpp |
| 17 | +_variant_t& operator=( const VARIANT& varSrc ); |
| 18 | +_variant_t& operator=( const VARIANT* pVarSrc ); |
| 19 | +_variant_t& operator=( const _variant_t& var_t_Src ); |
| 20 | +_variant_t& operator=( short sSrc ); |
| 21 | +_variant_t& operator=( long lSrc ); |
| 22 | +_variant_t& operator=( float fltSrc ); |
| 23 | +_variant_t& operator=( double dblSrc ); |
| 24 | +_variant_t& operator=( const CY& cySrc ); |
| 25 | +_variant_t& operator=( const _bstr_t& bstrSrc ); |
| 26 | +_variant_t& operator=( const wchar_t* wstrSrc ); |
| 27 | +_variant_t& operator=( const char* strSrc ); |
| 28 | +_variant_t& operator=( IDispatch* pDispSrc ); |
| 29 | +_variant_t& operator=( bool bSrc ); |
| 30 | +_variant_t& operator=( IUnknown* pSrc ); |
| 31 | +_variant_t& operator=( const DECIMAL& decSrc ); |
| 32 | +_variant_t& operator=( BYTE byteSrc ); |
| 33 | +_variant_t& operator=( char cSrc ); |
| 34 | +_variant_t& operator=( unsigned short usSrc ); |
| 35 | +_variant_t& operator=( unsigned long ulSrc ); |
| 36 | +_variant_t& operator=( int iSrc ); |
| 37 | +_variant_t& operator=( unsigned int uiSrc ); |
| 38 | +_variant_t& operator=( __int64 i8Src ); |
| 39 | +_variant_t& operator=( unsigned __int64 ui8Src ); |
15 | 40 | ``` |
16 | | -_variant_t& operator=( |
17 | | - const VARIANT& varSrc |
18 | | -); |
19 | | -
|
20 | | -_variant_t& operator=( |
21 | | - const VARIANT* pVarSrc |
22 | | -); |
23 | | -
|
24 | | -_variant_t& operator=( |
25 | | - const _variant_t& var_t_Src |
26 | | -); |
27 | | -
|
28 | | -_variant_t& operator=( |
29 | | - short sSrc |
30 | | -); |
31 | | -
|
32 | | -_variant_t& operator=( |
33 | | - long lSrc |
34 | | -); |
35 | 41 |
|
36 | | -_variant_t& operator=( |
37 | | - float fltSrc |
38 | | -); |
| 42 | +### Parameters |
39 | 43 |
|
40 | | -_variant_t& operator=( |
41 | | - double dblSrc |
42 | | -); |
| 44 | +*`varSrc`*\ |
| 45 | +A reference to a `VARIANT` from which to copy the content and `VT_*` type. |
43 | 46 |
|
44 | | -_variant_t& operator=( |
45 | | - const CY& cySrc |
46 | | -); |
| 47 | +*`pVarSrc`*\ |
| 48 | +A pointer to a `VARIANT` from which to copy the content and `VT_*` type. |
47 | 49 |
|
48 | | -_variant_t& operator=( |
49 | | - const _bstr_t& bstrSrc |
50 | | -); |
| 50 | +*`var_t_Src`*\ |
| 51 | +A reference to a `_variant_t` from which to copy the content and `VT_*` type. |
51 | 52 |
|
52 | | -_variant_t& operator=( |
53 | | - const wchar_t* wstrSrc |
54 | | -); |
| 53 | +*`sSrc`*\ |
| 54 | +A **`short`** integer value to copy. Given type `VT_BOOL` if `*this` is of type `VT_BOOL`. Otherwise, it's given type `VT_I2`. |
55 | 55 |
|
56 | | -_variant_t& operator=( |
57 | | - const char* strSrc |
58 | | -); |
| 56 | +*`lSrc`*\ |
| 57 | +A **`long`** integer value to copy. Given type `VT_BOOL` if `*this` is of type `VT_BOOL`. Given type `VT_ERROR` if `*this` is of type `VT_ERROR`. Otherwise, given type `VT_I4`. |
59 | 58 |
|
60 | | -_variant_t& operator=( |
61 | | - IDispatch* pDispSrc |
62 | | -); |
| 59 | +*`fltSrc`*\ |
| 60 | +A **`float`** numerical value to copy. Given type `VT_R4`. |
63 | 61 |
|
64 | | -_variant_t& operator=( |
65 | | - bool bSrc |
66 | | -); |
| 62 | +*`dblSrc`*\ |
| 63 | +A **`double`** numerical value to copy. Given type `VT_DATE` if `this` is of type `VT_DATE`. Otherwise, given type `VT_R8`. |
67 | 64 |
|
68 | | -_variant_t& operator=( |
69 | | - IUnknown* pSrc |
70 | | -); |
| 65 | +*`cySrc`*\ |
| 66 | +A `CY` object to copy. Given type `VT_CY`. |
71 | 67 |
|
72 | | -_variant_t& operator=( |
73 | | - const DECIMAL& decSrc |
74 | | -); |
| 68 | +*`bstrSrc`*\ |
| 69 | +A `BSTR` object to copy. Given type `VT_BSTR`. |
75 | 70 |
|
76 | | -_variant_t& operator=( |
77 | | - BYTE bSrc |
78 | | -); |
| 71 | +*`wstrSrc`*\ |
| 72 | +A Unicode string to copy, stored as a `BSTR` and given type `VT_BSTR`. |
79 | 73 |
|
80 | | -_variant_t& operator=( |
81 | | - char cSrc |
82 | | -); |
| 74 | +*`strSrc`*\ |
| 75 | +A multibyte string to copy, stored as a `BSTR` and given type `VT_BSTR`. |
83 | 76 |
|
84 | | -_variant_t& operator=( |
85 | | - unsigned short usSrc |
86 | | -); |
| 77 | +*`pDispSrc`*\ |
| 78 | +An `IDispatch` pointer to copy with a call to `AddRef`. Given type `VT_DISPATCH`. |
87 | 79 |
|
88 | | -_variant_t& operator=( |
89 | | - unsigned long ulSrc |
90 | | -); |
| 80 | +*`bSrc`*\ |
| 81 | +A **`bool`** value to copy. Given type `VT_BOOL`. |
91 | 82 |
|
92 | | -_variant_t& operator=( |
93 | | - int iSrc |
94 | | -); |
| 83 | +*`pSrc`*\ |
| 84 | +An `IUnknown` pointer to copy with a call to `AddRef`. Given type `VT_UNKNOWN`. |
95 | 85 |
|
96 | | -_variant_t& operator=( |
97 | | - unsigned int uiSrc |
98 | | -); |
| 86 | +*`decSrc`*\ |
| 87 | +A `DECIMAL` object to copy. Given type `VT_DECIMAL`. |
99 | 88 |
|
100 | | -_variant_t& operator=( |
101 | | - __int64 i8Src |
102 | | -); |
103 | | -
|
104 | | -_variant_t& operator=( |
105 | | - unsigned __int64 ui8Src |
106 | | -); |
107 | | -``` |
108 | | - |
109 | | -## Remarks |
| 89 | +*`byteSrc`*\ |
| 90 | +A `BYTE` value to copy. Given type `VT_UI1`. |
110 | 91 |
|
111 | | -The operator assigns a new value to the `_variant_t` object: |
| 92 | +*`cSrc`*\ |
| 93 | +A **`char`** value to copy. Given type `VT_I1`. |
112 | 94 |
|
113 | | -- **operator=(** *varSrc* **)** Assigns an existing `VARIANT` to a `_variant_t` object. |
| 95 | +*`usSrc`*\ |
| 96 | +An **`unsigned short`** value to copy. Given type `VT_UI2`. |
114 | 97 |
|
115 | | -- **operator=(** *pVarSrc* **)** Assigns an existing `VARIANT` to a `_variant_t` object. |
| 98 | +*`ulSrc`*\ |
| 99 | +An **`unsigned long`** value to copy. Given type `VT_UI4`. |
116 | 100 |
|
117 | | -- **operator=(** *var_t_Src* **)** Assigns an existing `_variant_t` object to a `_variant_t` object. |
| 101 | +*`iSrc`*\ |
| 102 | +An **`int`** value to copy. Given type `VT_INT`. |
118 | 103 |
|
119 | | -- **operator=(** *sSrc* **)** Assigns a **`short`** integer value to a `_variant_t` object. |
| 104 | +*`uiSrc`*\ |
| 105 | +An **`unsigned int`** value to copy. Given type `VT_UINT`. |
120 | 106 |
|
121 | | -- **operator=(** `lSrc` **)** Assigns a **`long`** integer value to a `_variant_t` object. |
| 107 | +*`i8Src`*\ |
| 108 | +An **`__int64`** or **`long long`** value to copy. Given type `VT_I8`. |
122 | 109 |
|
123 | | -- **operator=(** *fltSrc* **)** Assigns a **`float`** numerical value to a `_variant_t` object. |
| 110 | +*`ui8Src`*\ |
| 111 | +An **`unsigned __int64`** or **`unsigned long long`** value to copy. Given type `VT_UI8`. |
124 | 112 |
|
125 | | -- **operator=(** *dblSrc* **)** Assigns a **`double`** numerical value to a `_variant_t` object. |
126 | | - |
127 | | -- **operator=(** *cySrc* **)** Assigns a `CY` object to a `_variant_t` object. |
128 | | - |
129 | | -- **operator=(** *bstrSrc* **)** Assigns a `BSTR` object to a `_variant_t` object. |
130 | | - |
131 | | -- **operator=(** *wstrSrc* **)** Assigns a Unicode string to a `_variant_t` object. |
132 | | - |
133 | | -- **operator=(** `strSrc` **)** Assigns a multibyte string to a `_variant_t` object. |
134 | | - |
135 | | -- **operator=(** `bSrc` **)** Assigns a **`bool`** value to a `_variant_t` object. |
136 | | - |
137 | | -- **operator=(** *pDispSrc* **)** Assigns an `IDispatch*` object to a `_variant_t` object and calls `AddRef`. |
138 | | - |
139 | | -- **operator=(** *pIUnknownSrc* **)** Assigns an `IUnknown*` object to a `_variant_t` object and calls `AddRef`. |
| 113 | +## Remarks |
140 | 114 |
|
141 | | -- **operator=(** *decSrc* **)** Assigns a `DECIMAL` value to a `_variant_t` object. |
| 115 | +The `operator=` assignment operator clears any existing value, which deletes object types, or calls `Release` for `IDispatch*` and `IUnknown*` types. Then, it copies a new value into the `_variant_t` object. It changes the `_variant_t` type to match the assigned value, except as noted for **`short`**, **`long`**, and **`double`** arguments. Value types are copied directly. A `VARIANT` or `_variant_t` pointer or reference argument copies the assigned object's contents and type. Other pointer or reference type arguments create a copy of the assigned object. The assignment operator calls `AddRef` for `IDispatch*` and `IUnknown*` arguments. |
142 | 116 |
|
143 | | -- **operator=(** `bSrc` **)** Assigns a `BYTE` value to a `_variant_t` object. |
| 117 | +`operator=` invokes [`_com_raise_error`](../cpp/com-raise-error.md) if an error occurs. |
144 | 118 |
|
145 | | -**END Microsoft Specific** |
| 119 | +`operator=` returns a reference to the updated `_variant_t` object. |
146 | 120 |
|
147 | 121 | ## See also |
148 | 122 |
|
149 | | -[_variant_t Class](../cpp/variant-t-class.md) |
| 123 | +[`_variant_t` class](../cpp/variant-t-class.md) |
0 commit comments