RAII, value classes and implicit conversion
Bill Baxter
dnewsgroup at billbaxter.com
Tue Nov 14 18:23:09 PST 2006
Chris Nicholson-Sauls wrote:
>>
>> Structs are a lot like classes, except they can NOT:
>> - have virtual methods
>> - override inherited methods
>> (technically: they can't have VMT table)
>
> While in a certain sense true... I'd really like to avoid the C++
> situation where the only difference is where they get allocated.
The only difference between struct and class in C++ is the default
protection level. In a struct memebers are public by default, for
classes they're private by default. That's the only difference. And
also the inheritance in structs is public by default, and private for
classes.
And that's why it's really annoying that you can't generically forward
declare a class/struct without knowing which it is.
---foo.h----
class ForwardDeclared;
class Foo {
ForwardDeclared *f;
};
------------
This fails if ForwardDeclared turns out to be a struct. Grrr. Who
cares which it is?! They're the same freaking thing! All you need to
know, mr. dumb compiler, is that I've got a pointer, period.
(Maybe typename fixes this? Does anyone know?).
--bb
More information about the Digitalmars-d
mailing list