byval keyword to make objects act as value types
Craig Black
craigblack2 at cox.net
Sun Dec 23 09:04:56 PST 2007
>although adding those things and ctors/dtors to structs like you said
>would be just as good really. i got the impression that option was off
>the table though.
>should struct member functions & dtors be virtual by default?
Good question. Here's my philosophy about virtual by default. I am a
performance-oriented guy, and I prefer the compiler to NOT make functions
virtual when I don't explicitly say "virtual". For me, virtual by default
means I need to be more careful about overriding so something doesn't become
virtual accidentally.
Further, virtual by default prevents non-virtual overriding, which can be
used for high-performance compile-time polymorphism using templates.
That said, if this happens at all, Walter would probably use virtual by
default for consistency sake. Oh well, I guess it's not that big a deal.
If polymorphism is added to structs, it should be optional. I would have a
problem if the vtable pointer was included in structs that didn't have any
polymorphism. It should work like C++ structs and classes, where there is
no overhead for non-polymorphic types.
As for virtual destructors, I agree that they should be virtual by default,
but only if a type is polymorphic. Forgetting to make a destructor virtual
in C++ can cause subtle and annoying bugs. It's good that most C++
compilers issue warnings when a polymorphic type has a non-virtual
destructor. However, I would rather the compiler make it virtual for me.
-Craig
More information about the Digitalmars-d
mailing list