hey all.
i'm using g++, and want to extend a struct, like this:
typedef struct _first {
int a1;
} first;
typedef struct _second {
struct _first;
int b1;
} second;
so i can access first members from second, directly, like this:
second.a1 = 1;
this doesn't work for me in g++,
but works well on other compiler (pellesc),
from my memory, i think this is a standard,
so i wonder why it doesn't work in g++.
It depends on what you want, by your example output it looks like you want an "Is A" relationship.
"Is a" relationship:
1 2 3 4 5 6 7 8 9 10 11
struct First{
int a1;
};
struct Second : public First{
int b1;
};
//First is accessed like this...
Second obj;
obj.a1; //This is an "Is a" relationship
"Has a" relationship:
1 2 3 4 5 6 7 8 9 10 11 12
struct First{
int a1;
};
struct Second{
First first;
int b1;
};
//First is accessed like this...
Second obj;
obj.first.a1; //This is a "Has A" relationship
the best i would like to know,
is how to inherit, for both compilers C/C++,
i'm quiet sure this is possible, since this is a standard C syntax,
which C++ should support.
anyway, if for some reason this is impossible,
then i can solve it with conditional compliation.
i didn't check your replies yet, so i let you know, later.
no, i have both, and i need the same code to work on both, but it doesn't with G++.
the code is standard ANSI (i think), so the problem is with G++, not with my code,
since it compiles well with C Compiler.