Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. What is this message telling me?

What is this message telling me?

Scheduled Pinned Locked Moved Managed C++/CLI
c++questiondata-structureshelp
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Bert Fegyverneki
    wrote on last edited by
    #1

    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

    G 1 Reply Last reply
    0
    • B Bert Fegyverneki

      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

      G Offline
      G Offline
      Ghydo
      wrote on last edited by
      #2

      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 an unsigned 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 an int. Hope it helps!

      B 1 Reply Last reply
      0
      • G Ghydo

        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 an unsigned 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 an int. Hope it helps!

        B Offline
        B Offline
        Bert Fegyverneki
        wrote on last edited by
        #3

        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

        G 1 Reply Last reply
        0
        • B Bert Fegyverneki

          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

          G Offline
          G Offline
          Ghydo
          wrote on last edited by
          #4

          Hi Bert, reinterpret_cast can cast to anything you want: to cast to a unsigned int you can use reinterpret_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). If dictParameters[POINT_PARAM] is an array of unsigned int ^ your cast was correct and you should dereference pointParam to obtain the value, but if it is an array of string you have to convert it using int::Parse. How is dictParameters defined? I hope it is clearer! :)

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups