Struct Inheritence

2016-02-19 Thread user001 via Digitalmars-d-learn
Well struct don't have it, but i would like something like it but 
only for data, i don't need functions or anything like that just 
data.



struct A
{
int valueA;
}

struct B
{
A a;
int valueB;
}

struct C
{
B b;
int valueC;
}

C c;

c.b.a.valueA; // not elegant

B* b = &c.b;

b.a.valueA; // we can access A


// alternative 
--


struct A
{
int valueA;
}

struct B
{
int valueB;
}

struct C
{
A a;
B b;
int valueC;
}

C c;

c.a.valueA; // a bit more elegant but still not very, 
c.valueA would be prefered


B* b = &c.b;

b.? // can't access A, unless we do some hack that assumes B 
always follows A in the definition



Is there any way to do inheritance with structs, is there a 
reason why we can't extend structures like in C++?


Re: Struct Inheritence

2016-02-19 Thread user001 via Digitalmars-d-learn

Yes that's exactly what i needed, thanks!