Is this a pointer operation ?
-
I have a C(++) souce code line: UserTri* pNewVariable; ...where UserTri is a class. All this should declare a new variable of UserTri type. My question is: does this above equals to this below in C# ? UserTri pNewVariable; The "*" after the UserTri made me think that it might be a pointer, but then again in C# all classes are reference types so the "pointer operation" is actually just hidden here (in C#). True ?
-
I have a C(++) souce code line: UserTri* pNewVariable; ...where UserTri is a class. All this should declare a new variable of UserTri type. My question is: does this above equals to this below in C# ? UserTri pNewVariable; The "*" after the UserTri made me think that it might be a pointer, but then again in C# all classes are reference types so the "pointer operation" is actually just hidden here (in C#). True ?
desmond5 wrote: True ? yes :) top secret
-
I have a C(++) souce code line: UserTri* pNewVariable; ...where UserTri is a class. All this should declare a new variable of UserTri type. My question is: does this above equals to this below in C# ? UserTri pNewVariable; The "*" after the UserTri made me think that it might be a pointer, but then again in C# all classes are reference types so the "pointer operation" is actually just hidden here (in C#). True ?
If your C++ code is managed C++: yes, in fact it is. If your C++ code is unmanaged C++: no, it's not the same. Pointers in managed C++ are managed by the garbage collector, as are the reference types in C#. Hence you don't have to (and you will not be able to)delete them manually. Pointers in unmanaged C++, however, are completely at your mercy, so you have to take care of them via the delete operator.
-
I have a C(++) souce code line: UserTri* pNewVariable; ...where UserTri is a class. All this should declare a new variable of UserTri type. My question is: does this above equals to this below in C# ? UserTri pNewVariable; The "*" after the UserTri made me think that it might be a pointer, but then again in C# all classes are reference types so the "pointer operation" is actually just hidden here (in C#). True ?
Yes (but maybe no, if UserTri is actually a value type (like struct) rather than 'true' class). I'm an Assembler programmer at heart, and in cases like this, ask myself, "Is this storing an address (of, say, 4 bytes), or the value?" The C++ code is storing an address. The C# code stores address of classes & copy of variable for value types (simple data types & structs). I LOVE pointers, and regard C#'s reference (and C++'s, for that matter) as 'pointers in disguise'. Regards Brewman