The following code doesn't compile:
CComBSTR temp;
CMenu().GetMenuString(0, temp, 0);
but this does:
CComBSTR temp;
CMenu().GetMenuString(0, *&temp, 0);
Why?
Full code:
#include <atlbase.h>
extern CComModule _Module;
#include <atlapp.h>
#include <atlwin.h>
#include <atlctrls.h>
int main() {
CComBSTR temp;
CMenu().GetMenuString(0, *&temp, 0);
}
GetMenuString
signature (from atluser.h
, from WTL):
BOOL GetMenuString(UINT nIDItem, BSTR& bstrText, UINT nFlags) const;
Ideally, the second negative should change the sign of our original number (which is also negative). So, our original negative sign is changed into a positive sign when a negative is multiplied to it. Thus, As multiplying with negative will change the sign, a negative times a negative equal a positive.
The fact that the product of two negatives is a positive is therefore related to the fact that the inverse of the inverse of a positive number is that positive number back again.
A simpler algebraic proof Using the fact multiplication is commutative, a negative times a positive is also negative. Similarly, we can prove that a negative times a negative is a positive. Since we know that −ab is negative, and the sum of these two terms is 0, therefore (−a) × (−b) is positive.
Negative times positive is always negative This means that an expression with one negative number (like multiplying a negative number by a positive one) will always turn out negative. Otherwise, though, multiplying with negative numbers works just like multiplying positive numbers.
Because the unary operators &
and *
can be overloaded, which I guess CComBSTR
does.
* Update: *
For those who wonder how to get the address of a variable whose type has overloaded operator&
there is TR1's std::addressof
, and a Boost implementation of it for C++03 compatibility.
CComBSTR
might have overloaded the operator *
or operator &
to return a type which matches the parameter type received by GetMenuString()
So while *&x
is same as x
for built-in data types, it may not be the same for user defined types.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With