[erledigt] const static initialisieren
-
Hi!
Ich habe eine Klasse Matrix4x4, die eine 4x4-Matrix repräsentiert.
Nun möchte ich ein paar const static Matrix4x4 member haben, die bekannte Matrizen darstellen - wie z.B. die Identitätsmatrix:class Matrix4x4 { public: const static Matrix4x4 IDENTITY; static Matrix4x4& createIdentity(); ...Mit der Methode createIdentity() möchte ich IDENTITY initialisieren.
Wo und wie kann ich das machen? Ich habe es über den Konstruktor probiert mitMatrix4x4::Matrix4x4(...) : IDENTITY(createIdentity()) {...aber das geht nicht.
-
class Matrix4x4 { public: static Matrix4x4 Identity() { Matrix4x4 m; // bau identity return m; } }; int main() { Matrix4x4 E = Matrix4x4::Identity(); return 0; }oder was?
ach verlesen. Du meinst wohl eher sowas oder:
class Matrix { public: static const Matrix& Identity() { return E; } static Matrix createIdentity() { Matrix M; // ... return M; } private: const static Matrix E; }; const Matrix Matrix::E = Matrix::createIdentity();
-
Ja, letzteres meinte ich.
Super! Vielen Dank.