next up previous contents index
Next: Benutze inline mit Bedacht Up: 50 Ways to Improve Previous: Keine Referenzen auf lokale

Ganzahlige Klassenkonstanten

 

Klassenlokale Konstanten sind leider nicht möglich. Auch statische Datenelemente helfen nicht:

    class X
    { static const int BUFSIZ=100;  // FALSCH
      char buffer[BUFSIZ];
    };

Auch so geht es nicht:

    class X
    { static const int BUFSIZ;
      char buffer[BUFSIZ];      // FALSCH
    };
    const int X::BUFSIZ=100;

Was jedoch geht, sind klassenlokale Aufzählungstypen. Damit kann man wenigstens ganzahlige Konstanten implementieren:

 

    class X
    { enum {BUFSIZ = 100};
      char buffer[BUFSIZ];      // OK
    };


next up previous contents index
Next: Benutze inline mit Bedacht Up: 50 Ways to Improve Previous: Keine Referenzen auf lokale

Peter Pfahler, 1997