tags:

views:

68

answers:

1

How to insert into the vector assigned inside a structure ? The code is this that I have written

struct state{
  int time_taken;
  vector<int>time_live(1);
  string loc_name;
  vector<string>loc(1);
};
state A[100];

A[flag1]->loc.insert(flag2);
A[flag1]->time_live.insert(time);

A[flag2]->loc.insert(flag1);
A[flag2]->loc.insert(time);

The error i am getting is this

kris_UCS.cpp:11: error: expected identifier before numeric constant
kris_UCS.cpp:11: error: expected ‘,’ or ‘...’ before numeric constant
kris_UCS.cpp:13: error: expected identifier before numeric constant
kris_UCS.cpp:13: error: expected ‘,’ or ‘...’ before numeric constant
kris_UCS.cpp: In function ‘int main()’:
kris_UCS.cpp:60: error: base operand of ‘->’ has non-pointer type ‘state’
kris_UCS.cpp:61: error: base operand of ‘->’ has non-pointer type ‘state’
kris_UCS.cpp:63: error: base operand of ‘->’ has non-pointer type ‘state’
kris_UCS.cpp:64: error: base operand of ‘->’ has non-pointer type ‘state’
+7  A: 
struct state
{
    int time_taken;
    vector<int> time_live; // no parenthesis
    string loc_name;
    vector<string> loc; // no parenthesis
};

state A[100];

A[flag1].loc.push_back(flag2);
A[flag1].time_live.push_back(time);

A[flag2].loc.push_back(flag1);
A[flag2].loc.push_back(time);
ybungalobill
I still have the errors regarding the usage of this "->"
mekasperasky
To be read again: in my code there is no `->` operator at all.
ybungalobill
@mekasperasky: Where? He's never used that syntax.
DeadMG
@mekasperasky: Why would you use `->` here ? I don't get it.
ereOn
@mekasperasky: Change `->` to `.`
Naveen