Get which derived class an object is if it's stored in an array of its base class

Morimur55 via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Jul 15 08:34:02 PDT 2017


On Saturday, 15 July 2017 at 14:46:17 UTC, Adam D. Ruppe wrote:
> On Saturday, 15 July 2017 at 14:36:40 UTC, Morimur55 wrote:
>> ...let me try that again without accidentally sending it 
>> before I'd finished...
>
> tab on the web interface is so useful... but so annoying 
> sometimes too.
>
>> ...and I think my problem is actually that redeclared static 
>> variables update on the base class if called from a base class 
>> function?
>
> Yeah, member variables are always directly attached to the 
> class they are on, no virtualness there.
>
> Why are you redeclaring it? A virtual property getter/setter 
> pair might be what you need.


I'm reading in some objects from yaml, assigning them incremental 
ids per type so they can be queried and changed at runtime with 
Lua by another programmer, and then spat back out as yaml when 
they're done.

Mostly redeclaring because I tried it, didn't get a compiler 
error, so I thought it'd just work the way I imagined it would. 
What can I say, I like to live dangerously. :p

Thanks for your help, I'll put in some virtual properties and 
hope for the best.



More information about the Digitalmars-d-learn mailing list