|
-
Sep 8th, 2008, 02:04 PM
#1
[RESOLVED] Some basic questions abut C++/CLI
Hello to everyone, I am trying to get to know C++/CLI and I have some questions. Just to let you know I have VB.Net background and I also have taken some C++ classes some years before. I hope someone can shade a light on my questions. Here it goes:
First, what is exactly the deference between the reference class and the value class? I mean why we need to declare the “ref” or “value” classes if we pass the arguments as ref or value in VB.Net. It is a little bit confusing for me to have a type as referenced and value.
Second, what is this [int main(array<System::String ^> ^args)] line representing? My guess is that the argument is a string array and it may contain the command line for this app passed when the app starts. Is this right?
Also I have a question about “^”. What I read from MSDN the symbol “^” directs the compiler to create handle for the object in the managed garbagecollecter heap so that it can be cleaned when there are no references to this object. Is this right? And also why they are two on that line? I mean one is not enough having it in front of “args”? Is it because the string data type is an array of chars in C++ and it its self should have a handle in the heap? Is this correct?
The questions may be very simple but I tried to get the answers on MSDN and still they are confusing for me. I would appreciate for any help.
Thanks in advance,
VBDT
-
Sep 8th, 2008, 02:22 PM
#2
Re: Some basic questions abut C++/CLI
 Originally Posted by VBDT
First, what is exactly the deference between the reference class and the value class? I mean why we need to declare the “ref” or “value” classes if we pass the arguments as ref or value in VB.Net. It is a little bit confusing for me to have a type as referenced and value.
A value type variable is a variable that stores a value, such as an integer or a double. A reference type variable points to a memory block where the data is located, thus if you send this variable to another method for instance, any modifications done on it will also be done on the original variable, as they point to the same memory reference.
 Originally Posted by VBDT
Second, what is this [int main(array<System::String ^> ^args)] line representing? My guess is that the argument is a string array and it may contain the command line for this app passed when the app starts. Is this right?
Thats correct, it is a managed string array that will contain any arguments passed to the executable.
 Originally Posted by VBDT
Also I have a question about “^”. What I read from MSDN the symbol “^” directs the compiler to create handle for the object in the managed garbagecollecter heap so that it can be cleaned when there are no references to this object. Is this right?
That is also correct
 Originally Posted by VBDT
And also why they are two on that line? I mean one is not enough having it in front of “args”? Is it because the string data type is an array of chars in C++ and it its self should have a handle in the heap? Is this correct?
The reason is that the array class is a managed type and needs to be handled by the managed garbagecollector, the same goes for the System::String managed class.
You'll see that with unmanaged classes you do not use the ^, as those are not handled by the garbagecollector.
Last edited by Atheist; Sep 8th, 2008 at 03:22 PM.
-
Sep 8th, 2008, 02:44 PM
#3
Re: Some basic questions abut C++/CLI
Thank you Atheist, you defenatly cleard some confusion I had. One more question I would like to ask. As what I read about “ref class” and “value class” it appears that this are only used in C++/CLI projects and this keywords specify that this classes (data types) are managed and these keywords are not used in native C++ code. Is this the case?
-
Sep 8th, 2008, 03:16 PM
#4
Re: Some basic questions abut C++/CLI
There is no such thing as a value class.
There are value types and reference types. The terminology is important. Classes are reference types and structs are value types.
I don't live here any more.
-
Sep 8th, 2008, 03:29 PM
#5
Re: Some basic questions abut C++/CLI
 Originally Posted by wossname
There is no such thing as a value class.
There are value types and reference types. The terminology is important. Classes are reference types and structs are value types.
Yes, you are right! I just put “value class” because this is how they are declared, but you are right about the terminology since I think I understand now what these keywords stand for. So in simple words value types are structure types comparing to VB.Net. And the reference types are the classes compared to VB.Net.
Thank you for pointing it out!
-
Sep 8th, 2008, 07:57 PM
#6
Re: Some basic questions abut C++/CLI
 Originally Posted by wossname
There is no such thing as a value class.
There are value types and reference types. The terminology is important. Classes are reference types and structs are value types.
In C++/CLI, "ref class" and "ref struct" are reference types. "value class" and "value struct" (and "enum class") are value types. You can't make the same distinction that you can make in C#.
C++/CLI carries on the long-standing C++ tradition of virtually no distinction between 'class' and 'struct' (unlike C#, the only distinction is the default access modifier of the members).
-
Sep 10th, 2008, 02:14 PM
#7
Re: [RESOLVED] Some basic questions abut C++/CLI
Fair enough, some features of C++ are more dubious than others though. I'd regard value classes as a bit of a hack.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|