### Example - Static Const vector<vector>

Many People ask me all the time about how initialize a static vector, const vector, etc...
So here is a really complex example, and this way always works. So don't ask again :)

Atype.h
 ``12345678910111213141516`` ``````class Atype { public: Atype(Btype vB): mB(vB) {} virtual ~Atype(void){} const Btype& getB(void) const { return mB; } //... private: Btype mB; //... };``````

Ctype.h
 ``12345678910111213141516171819`` ``````class Ctype { public: Ctype(){} virtual ~Ctype(void){} struct Values{ Atype vA; //... Values(a) : vA(a) {} } }; private: static std::vector< std::vector > getAVector(); static const std::vector< std::vector > aVector; };``````

Ctype.cpp
 ``12345678910111213141516171819`` ``````const std::vector< std::vector > Ctype::aVector = Ctype::getAVector(); std::vector< std::vector > Ctype::getAVector() { std::vector< std::vector > aV; std::vector aV1, aV2; // Let's say Btype contains 2 string aV1.push_back(Values(Atype(Btype("a","b")); aV1.push_back(Values(Atype(Btype("c","d")); aV2.push_back(Values(Atype(Btype("a","e")); aV2.push_back(Values(Atype(Btype("a","f")); aV.push_back(aV1); aV.push_back(aV2); return aV; }``````

After this you can get the Btype mB data fast and const with getB()
Last edited on
Really? Where's Btype?
Topic archived. No new replies allowed.