Code:
#include <vector>
#include <iostream>
using std::cout;
using std::vector;
enum {DATASIZE = 20};
typedef unsigned char data_t[DATASIZE];
int setvalue(UInt8 *pValue)
{
for (int i = 0; i < DATASIZE; i++)
pValue[i] = '1' + i;
return 0;
}
void displayvalue(UInt8 *pValue)
{
for (int i = 0; i < DATASIZE; i++)
cout << pValue[i] << "\n";
}
int main(int argc, char* argv[])
{
enum {MAX_PROC = 5, MAX_OBJECT = 10000};
// I want to use vector instead of array because the array size is determined by a variable
//data_t data[MAX_PROC][MAX_OBJECT];
vector<data_t> v[MAX_PROC] (10); // compile error here!
for (int i = 0; i < MAX_PROC; i++) {
setvalue(v[i][0]);
}
cout << "data\n";
for (i = 0; i < MAX_PROC; i++) {
displayvalue(v[i][0]);
}
return 0;
}
The above program is a test program to test how to use vector instead of array for my own project, so the setvalue and displayvalue function is simplied for test purpose (they are actually functions from another library which I cannot change).
I want to keep data_t defined as an array of unsigned char.
There is a compile error for the above program:
error: new : cannot specify initializer for arrays
How to fix this compile error?
Thanks in advance.