accessing vector of struct

hello guys,

I have a struct:

1
2
3
4
5
6
struct table {
        std::string field1[10];
        std::string field2[10];
        std::string field3[10];
        std::string field4[10];
    };


then I have a vector of that struct:

vector <table> *tableList;

then I assign some memory to vector pointer:

tableList = (vector <table> *)shmat(id2, 0, 0);

now, how can I access the values of that vector and assign values to them?

I am doing this way, but getting segmentation fault:

(*tableList)[0]->field1[0] = "test";


Anyone?

thanks!
You're putting the array sizes in the wrong spot. It should be:
1
2
3
4
5
6
struct table {
    std::string[10] field1;
    std::string[10] field2;
    std::string[10] field3;
    std::string[10] field4;
};
What is shmat and what does it return? I doubt you should use a cast here. Don't use casts if you don't know what you are doing. Often there is no reason to use a pointer to a vector. Are you sure you really need a pointer here?
Topic archived. No new replies allowed.