Hi,
I'm trying to define some consts to use as interface for a class...
The point is, I have to define const arrays of strings (that is a matrix), but after many years of C++ programming, this is actually the first time that I have such a task...
so I need a refresh...
The following code:
const char CONNECTIONS_AMOUNT=2;
const char DB[CONNECTIONS_AMOUNT-1][] = {"db1","db2"};
const char USERNAME[CONNECTIONS_AMOUNT-1][] = {"root1","root2"};
const char PASSWORD[CONNECTIONS_AMOUNT-1][] = {"admin","admin"};
const char HOST[CONNECTIONS_AMOUNT-1][] = {"localhost","localhost"};
const char CONNECTIONS_AMOUNT=2;
const char DB[CONNECTIONS_AMOUNT-1][] = {"db1","db2"};
const char USERNAME[CONNECTIONS_AMOUNT-1][] = {"root1","root2"};
const char PASSWORD[CONNECTIONS_AMOUNT-1][] = {"admin","admin"};
const char HOST[CONNECTIONS_AMOUNT-1][] = {"localhost","localhost"};
To copy to clipboard, switch view to plain text mode
doesn't work and the compiler complains:
multidimensional arrays must have bounds for all dimensions except the first
so following a suggestion I found on the net:
const char CONNECTIONS_AMOUNT=2;
const char DB[][CONNECTIONS_AMOUNT] = {"db1","db2"};
const char USERNAME[][CONNECTIONS_AMOUNT] = {"root1","root2"};
const char PASSWORD[][CONNECTIONS_AMOUNT] = {"admin","admin"};
const char HOST[][CONNECTIONS_AMOUNT] = {"localhost","localhost"};
const char CONNECTIONS_AMOUNT=2;
const char DB[][CONNECTIONS_AMOUNT] = {"db1","db2"};
const char USERNAME[][CONNECTIONS_AMOUNT] = {"root1","root2"};
const char PASSWORD[][CONNECTIONS_AMOUNT] = {"admin","admin"};
const char HOST[][CONNECTIONS_AMOUNT] = {"localhost","localhost"};
To copy to clipboard, switch view to plain text mode
and now the compiler complains:
initializer-string for array of chars is too long
(perhaps because so it expects arrays of 2 chars, that is CONNECTIONS_AMOUNT).
So, what is the simple solution and the stupid mistake for this?
Thank you for your time
Bookmarks