
Signature
Kind regards,
Bruno van Dooren MVP - VC++
http://msmvps.com/blogs/vanDooren
bruno_nos_pam_van_dooren@hotmail.com
> > I'm coding a layer into my application using CLI, between a unmanaged
> > and a c# layer. So, I have to marshal some unmanaged c++ structures
[quoted text clipped - 22 lines]
> http://msmvps.com/blogs/vanDooren
> bruno_nos_pam_van_doo...@hotmail.com
I'm not sure I understand. Why wouldn't I just use a CLI class then.
What's the difference? Is there any real benefit though?
Ben Voigt - 20 Apr 2007 18:32 GMT
> I'm not sure I understand. Why wouldn't I just use a CLI class then.
> What's the difference? Is there any real benefit though?
Are you asking about "ref struct vs ref class" or "ref struct vs native
class" or "ref struct vs value struct"?
ref struct and ref class are related in the same way as native struct and
native class -- there is no runtime difference. The only thing affected is
that struct, ref struct, and value struct all start with implicit "public:"
and class, ref class, and value class all start with implicit "private:".
ref class and ref struct are both C++/CLI equivalents to C# struct, all
three generate a garbage collected pass-by-ref CLR type, and all three have
different default member visibility.
Tamas Demjen - 20 Apr 2007 18:57 GMT
> ref class and ref struct are both C++/CLI equivalents to C# struct
I think you meant C# class.
Tom
Ben Voigt - 20 Apr 2007 19:38 GMT
>> ref class and ref struct are both C++/CLI equivalents to C# struct
>
> I think you meant C# class.
Yes indeed.
ref class and ref struct are both C++/CLI equivalents to C# class
value class and value struct are both C++/CLI equivalents to C# struct
Thanks for calling out my typo.
Tamas Demjen - 20 Apr 2007 18:55 GMT
> I'm not sure I understand. Why wouldn't I just use a CLI class then.
> What's the difference? Is there any real benefit though?
C++/CLI -------> C#
====================
ref class -----> class
ref struct ----> class
value class ---> struct
value struct --> struct
The C++/CLI keyword "ref" always indicates a reference type (C# class),
while the "value" keyword always refers to a value type (C# struct).
What confuses you is that in C# class and struct mean completely
different things than in C++. In C++, the only difference between class
and struct is whether members are public or private by default. In C#,
on the other hand, a class is a reference type, and a struct is a value
type, and they have nothing to do with public vs private access.
Tom