static std::vector
-
Warum spuckt der Linker eine Fehlermeldung aus, wenn ich versuche einen static std:vector zu benutzen? Also z.B. folgendes funktioniert nicht (unresolved external symbol):
class B { public: static std::vector<int> a; B(); }; B::B() { a.push_back(1); }
-
Du musst ihn erst definieren.
-
Ah, ok... C++ ist doof, alles muss man doppelt schreiben.
-
#ifndef B_HXX #define B_HXX #include <vector> class B { public: static std::vector<int> a; B(); }; #endif#include "B.hxx" ///B.cxx std::vector<int> B::a; B::B() { a.push_back(1); }Das dürfte Funktionieren.
-
ne. die definition muss in eine *.cpp sonst macht der Linker später Probleme.