std::vector<std::pair<std::string > >
can be used to store a list of a couple of lines. Is there a similar way to store a list of string triplets?
One way I can think of is to use std::vector
std::vector<std::vector<std::string > > v (4, std::vector<std::string> (3));
but this will not allow me to use manual first and second accessors.
So I wrote my own class
#include <iostream> #include <vector> using namespace std; template <class T> class triad { private: T* one; T* two; T* three; public: triad() { one = two = three =0; } triad(triad& t) { one = new T(t.get1()); two = new T(t.get2()); three = new T(t.get3()); } ~triad() { delete one; delete two; delete three; one = 0; two = 0; three = 0; } T& get1() { return *one; } T& get2() { return *two; } T& get3() { return *three; } }; int main() { std::vector< triad<std::string> > v; }
I have two questions
- Is there any way to improve class code?
- Is there a better way to store string triplets than the three methods described above?
source share