Arrays von static const members intialisiern
-
Hallo,
bei
class DataStreamExcept : public Exception { protected: static const std::string codes[] = { "Cannot open stream", "Cannot close stream" }; static const std::string gg = "3423"; };spuckt mir der gcc folgendes aus:
stream.cpp:28: error: a brace-enclosed initializer is not allowed here before ‘{’ token stream.cpp:31: error: invalid in-class initialization of static data member of non-integral type ‘const std::string []’ stream.cpp:32: error: invalid in-class initialization of static data member of non-integral type ‘const std::string’Ich kann mir nicht vorstellen, dass das grundsätzlich nicht funktioniert...
Was mache ich hier flasch?
-
Hallo
Die statischen Member müßen außerhalb der Klasse initialisert werden
// Header class DataStreamExcept : public Exception { protected: static const std::string codes[2]; static const std::string gg; }; // Implementation const std::string DataStreamExcept::codes[] = { "Cannot open stream", "Cannot close stream" }; const std::string DataStreamExcept::gg = "3423";bis bald
akari
-
Ahhh...
Funktioniert wunderbar, vielen Dank!