What is this message telling me?
-
Hi, I'm new to C++/CLI and I am getting compiler errors in a DLL appliction I am writing.... The DLL is passed in a text string from the calling application which needs to be cast to an unsigned int.... unsigned int^ pointParam = reinterpret_cast<unsigned int^>(dictParameters[POINT_PARAM]); Then I am using the integer value to create an array of double values but I need to increase the value by 2 so I thought I could add it in the array declaration statement... sagXArray = gcnew array<double>(pointParam + 2); I am getting the following compile error... 1>.\StrandedWireSag.cpp(42) : error C2676: binary '+' : 'System::UInt32 ^' does not define this operator or a conversion to a type acceptable to the predefined operator Why is the compiler unhappy about adding two values in a declaration? Thanks
-
Hi, I'm new to C++/CLI and I am getting compiler errors in a DLL appliction I am writing.... The DLL is passed in a text string from the calling application which needs to be cast to an unsigned int.... unsigned int^ pointParam = reinterpret_cast<unsigned int^>(dictParameters[POINT_PARAM]); Then I am using the integer value to create an array of double values but I need to increase the value by 2 so I thought I could add it in the array declaration statement... sagXArray = gcnew array<double>(pointParam + 2); I am getting the following compile error... 1>.\StrandedWireSag.cpp(42) : error C2676: binary '+' : 'System::UInt32 ^' does not define this operator or a conversion to a type acceptable to the predefined operator Why is the compiler unhappy about adding two values in a declaration? Thanks
The compiler complains because you are trying to add a number with a reference (a reference is like a C++ pointer, but it "points" to a garbage collected object).
unsigned int ^
is a reference to anunsigned int
, so you should dereference it to get the actual value:sagXArray = gcnew array<double>(*pointParam + 2);
But this will not work if you pass a number as a string (ex. "135"), you have to convert the string to a number using the method
int::Parse
:int pointParam = int::Parse(dictParameters[POINT_PARAM]);
sagXArray = gcnew array<double>(pointParam + 2);Note that in this case I'm not dereferencing
pointParam
because it is declared as anint
. Hope it helps! -
The compiler complains because you are trying to add a number with a reference (a reference is like a C++ pointer, but it "points" to a garbage collected object).
unsigned int ^
is a reference to anunsigned int
, so you should dereference it to get the actual value:sagXArray = gcnew array<double>(*pointParam + 2);
But this will not work if you pass a number as a string (ex. "135"), you have to convert the string to a number using the method
int::Parse
:int pointParam = int::Parse(dictParameters[POINT_PARAM]);
sagXArray = gcnew array<double>(pointParam + 2);Note that in this case I'm not dereferencing
pointParam
because it is declared as anint
. Hope it helps!Hi Ghydo, So, "reinterpret_cast" will cast to a reference (pointer), while "int::Parse" casts to a value. Is that correct? Thanks for the help! regards, Bert
-
Hi Ghydo, So, "reinterpret_cast" will cast to a reference (pointer), while "int::Parse" casts to a value. Is that correct? Thanks for the help! regards, Bert
Hi Bert,
reinterpret_cast
can cast to anything you want: to cast to aunsigned int
you can usereinterpret_cast<unsigned int^>
. (MSDN[^])int::Parse
is a method that takes a string and converts it (not cast) into its integer value (string "135" --> int 135). IfdictParameters[POINT_PARAM]
is an array ofunsigned int ^
your cast was correct and you should dereferencepointParam
to obtain the value, but if it is an array ofstring
you have to convert it usingint::Parse
. How isdictParameters
defined? I hope it is clearer! :)