On 2010-05-24 00.06, bearophile wrote:
Andrei Alexandrescu:
1. Using a class makes implementing members easier because there's no
need to do work through an additional member. With a struct, you need a
pimpl approach. For example:
struct Array {
struct Impl {
...
}
Impl * impl;
...
@property length() const { return impl->length; }
...
}
I am far from being an expert as you, and while I have read about the PImpl in
C++, I don't understand what you are saying here. I am sorry.
3. The creation syntaxes are different.
In C# you use 'new' for both structs allocated on the stack and classes
allocated on the heap:
http://msdn.microsoft.com/en-us/library/51y09td4%28VS.71%29.aspx
I've never liked that, always thinking that it maybe allocating on the heap.
Let me note that I have reached the conclusion that containers should
be at best reference types, with a meta-constructor Value!(C) that takes
a container C and makes it into a value type.
Does Value!() use static introspection and placement new to instantiate the
given class on the stack? :-)
Bye and thank you,
bearophile
--
/Jacob Carlborg