DMD OSX / Segfault 11
anonymous via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Feb 3 05:29:15 PST 2016
On 03.02.2016 14:16, Robert M. Münch wrote:
> Well, it should of course be:
>
> BaseOperator: Value {
> }
Still missing "class". I know I'm being pedantic, but if you're being
sloppy here, how do I know that you're not being sloppy where it matters?
>> Casting between class types that have an inheritance relation, like
>> Value and BaseOperator, does make sense (upcat/downcast).
>
> Yes, that's what I need.
Do that then. Cast between class types. Pointers don't by you anything here.
>> If anything, you should be casting between Value* and BaseOperator*
>> (both pointer types) if you want to do something with pointers.
>
> I tried this, but that doesn't work either.
Yeah, you can't check if the downcast succeeded this way. Casts between
pointers always succeed (and then fail horribly at run-time).
>> But you very seldom need pointers to class references. Just return
>> Value from get, and cast to BaseOperator.
>
> But am I not getting a copy then? I want to avoid copying objects as
> much as possible.
No, you're not getting a copy. Classes are reference types. That means,
variables of class types are references already. They're pointers in
disguise.
More information about the Digitalmars-d-learn
mailing list