I'm having a little issue with vectors. From what I understand, push_back()
will copy the argument and insert the copy in the vector.
struct BridgeData
{
string name;
string type;
};
For a simple aggregate class such as mine, the copy of an object should be made by copying both fields.
for ( int i = 0; i<len; i++)
{
BridgeData data = {grp.get(1+i).asString().c_str()};
v.push_back(data);
cout << v[i].name << endl;
}
with vector<BridgeData> &v
.
When I print data.name
, I get the value I used in the braced list but when I print v[i].name
, the field appears to be empty... Is the default copy "constructor" for such aggregate classes default initializing all fields?
EDIT:
Here's more code if that was not enough. I've got a class which contains as a data member vector<BridgeData> yarpGroups
. I then pass it as a reference in the body of a method from the same class : readBridgeDataVector(bGeneral,"yarpgroups",yarpGroups,numberOfYarpGroups);
.
Please ignore the other arguments as they are irrelevant (I am sure of it).
The earlier snipped is from this function :
void readBridgeDataVector(Bottle &rf, string name, vector<BridgeData> &v, int len)
{
v.resize(len);
if(rf.check(name.c_str()))
{
Bottle &grp = rf.findGroup(name.c_str());
for ( int i = 0; i<len; i++)
{
BridgeData data = {grp.get(1+i).asString().c_str(),"float"};
v.push_back(data);
cout << v[0].name << endl;
}
}
else
{
cout << "Could not find parameters for " << name << ". "
<< "Setting everything to null by default" << endl;
}
}