[C/C++] struct Vererbung

Enumerator

Mitglied Kamel
Hi,

Welches der Beispiele erzeugt für C wie C++ das gleiche Speicher-Layout?
Leider sind mir Herrn Stroustrup's Angaben nicht präzise genug - mag das vielleicht daran liegen dass man ohne den Compiler zu kennen die Frage nicht beantworten kann?
C++:
struct alpha {
#ifdef __cplusplus
    alpha(int a = 0, char b = '\0' ) throw(): _a(a), _b(b) {}
#endif
    int _a;
    char _b;
};

/* Beispiel 1 */
struct beta
#ifdef __cplusplus
: public alpha {
    beta(int a = 0, char b = '\0', float c = -1.F) throw(): alpha(a, b), _c(c) {}
#else
{   struct alpha alpha; /* <= !? */
#endif
    float _c; 
};

/* Beispiel 2 */
struct beta
#ifdef __cplusplus
: public alpha {
    beta(int a = 0, char b = '\0', float c = -1.F) throw(): alpha(a, b), _c(c) {}
#else
{   int _a; /* <= ?! */
    char _b;  /* <= ?! */
#endif
    float _c; 
};

Gruß
Enum

[NATCHTRAG]
Lasst mich raten: klein Enum doof; hat vergessen dass dank Padding beide Strukturen das gleiche Abbild erzeugen?!
 
Zuletzt bearbeitet:
Zurück