How to best do error lookups.

I'm trying to implement a 2-dimensional error lookup table, where each error ID has a (string) description and a 'Fatal' tag. What is the best way to do this? I am rather new to c++, and only a hobbyist, but I don't want simple solutions that I have to un-learn later.

My current solution is to have 2 vectors of vectors, to hold the description and 'fatal' tag. To accomplish this, I am using the following code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
class errinfo
{
    public:
    std::vector<std::vector<std::string> > ErrTable;
    std::vector<std::vector<bool> > ErrFatal;
    errinfo();
};

errinfo::errinfo()
{
    ErrTable.resize(255);
    for (int i = 0; i < ErrTable.size( ); i++)
        ErrTable[i].resize(255);

    ErrFatal.resize(255);
    for (int i = 0; i < ErrFatal.size( ); i++)
        ErrFatal[i].resize(255);
// . . .   Initializing the entries
}

I want to know if this is the best way to do this.
Last edited on
Maybe it can be done the following way

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
struct ErrorInfo
{
   size_t errorID;
   bool errorTag;
   std::string errorDescription;
};

struct ErrorOrder
{
   bool operator ()( const ErrorInfo &err1, const ErrorInfo &err2 ) const
   {
      return ( err1.errorID < err2.errorID );
   }
};


const std::set<ErrorInfo, ErrorOrder> errorTable =
   { { 1, true, "The first error" }, { 2, true, "The second error" }, { 3, false, "The third error" } };
 
Is that still a two dimensionally indexed array? I can't tell. I'm sorry if this is obvious, but I don't see it. I want to be able to reference error 2:3. I am looking for the simplest, most efficient solution.
Topic archived. No new replies allowed.