Pointer help
-
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 beSystem::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."
-
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 beSystem::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."
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:
-
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 beSystem::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."
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.