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. C#
  4. Pointer help

Pointer help

Scheduled Pinned Locked Moved C#
helpcsharpc++
3 Posts 3 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.
  • J Offline
    J Offline
    jacobjordan
    wrote on last edited by
    #1

    Here's my problem. I have this line of code in an unsafe context:

    TreeNode* Current = null;

    it gives me an error that says "Cannot take the address of, get the size of, or declare a pointer to a managed type ("System.Windows.Forms.TreeNode")" The C++ equivalent of that line would be

    System::Windows::Forms::TreeNode *Current = 0;

    and in C++, i can avoid that error by using the '^' operator like so

    System::Windows::Forms::TreeNode^ *Current = 0;

    however, i know little to nothing about C++, and i have no idea what the '^' operator does. If anyone knows a way to implement this in C#, please let me know.

    void Play() { try { throw Ball(); } catch (Glove) { } finally { Play(); } } "Failure is only the opportunity to begin again, this time more wisely." "Don't ask for a light load, but rather ask for a strong back."

    M G 2 Replies Last reply
    0
    • J jacobjordan

      Here's my problem. I have this line of code in an unsafe context:

      TreeNode* Current = null;

      it gives me an error that says "Cannot take the address of, get the size of, or declare a pointer to a managed type ("System.Windows.Forms.TreeNode")" The C++ equivalent of that line would be

      System::Windows::Forms::TreeNode *Current = 0;

      and in C++, i can avoid that error by using the '^' operator like so

      System::Windows::Forms::TreeNode^ *Current = 0;

      however, i know little to nothing about C++, and i have no idea what the '^' operator does. If anyone knows a way to implement this in C#, please let me know.

      void Play() { try { throw Ball(); } catch (Glove) { } finally { Play(); } } "Failure is only the opportunity to begin again, this time more wisely." "Don't ask for a light load, but rather ask for a strong back."

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #2

      C++ won't help here. You can't take the address of a managed object in either language. In C++/CLI, ^ indicates a handle to a managed object. You can get the address of the handle but not the address of the object. Mark

      Mark Salsbery Microsoft MVP - Visual C++ :java:

      1 Reply Last reply
      0
      • J jacobjordan

        Here's my problem. I have this line of code in an unsafe context:

        TreeNode* Current = null;

        it gives me an error that says "Cannot take the address of, get the size of, or declare a pointer to a managed type ("System.Windows.Forms.TreeNode")" The C++ equivalent of that line would be

        System::Windows::Forms::TreeNode *Current = 0;

        and in C++, i can avoid that error by using the '^' operator like so

        System::Windows::Forms::TreeNode^ *Current = 0;

        however, i know little to nothing about C++, and i have no idea what the '^' operator does. If anyone knows a way to implement this in C#, please let me know.

        void Play() { try { throw Ball(); } catch (Glove) { } finally { Play(); } } "Failure is only the opportunity to begin again, this time more wisely." "Don't ask for a light load, but rather ask for a strong back."

        G Offline
        G Offline
        Guffa
        wrote on last edited by
        #3

        To get a pointer to an object on the heap, you have to fix in to a specific address so that the garbage collector is no longer allowed to move it around in memory:

        fixed (TreeNode* Current = null) {
        // here you can use the pointer
        }

        Why do you need a pointer to a TreeNode anyway?

        Despite everything, the person most likely to be fooling you next is yourself.

        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