A
Andrea Crotti
I have a situation where the default value for an object is not so
simple, so I ended up doing
PadCoordinate:adCoordinate()
{
for (int i=0; i < GLOBALS::num_landmarks; ++i) {
coord.push_back(NOT_CONNECTED);
}
}
it's just a vector of elements.
Now I'm hunting a bug and I basically understood what the problem is.
In one situation (my tests)
PadCoordinate pc;
pc.coord.size() == 3 (for example)
but in the real world program
PadCoordinate pc;
pc.coord.size() == 0
So actually that thing is not executed "in time".
So first of all what could be the problem?
Second I thought something like this
static vector<coord_t> makeEmpty() {
vector<coord_t> tmp;
for (int i=0; i < GLOBALS::num_landmarks; ++i) {
tmp.push_back(NOT_CONNECTED);
}
return tmp;
}
and then the constructor becomes
PadCoordinate:adCoordinate() : coord(PadCoordinate::makeEmpty())
does it make sense? Or is better to create a static variable which
represents the default value copy and copy it?
simple, so I ended up doing
PadCoordinate:adCoordinate()
{
for (int i=0; i < GLOBALS::num_landmarks; ++i) {
coord.push_back(NOT_CONNECTED);
}
}
it's just a vector of elements.
Now I'm hunting a bug and I basically understood what the problem is.
In one situation (my tests)
PadCoordinate pc;
pc.coord.size() == 3 (for example)
but in the real world program
PadCoordinate pc;
pc.coord.size() == 0
So actually that thing is not executed "in time".
So first of all what could be the problem?
Second I thought something like this
static vector<coord_t> makeEmpty() {
vector<coord_t> tmp;
for (int i=0; i < GLOBALS::num_landmarks; ++i) {
tmp.push_back(NOT_CONNECTED);
}
return tmp;
}
and then the constructor becomes
PadCoordinate:adCoordinate() : coord(PadCoordinate::makeEmpty())
does it make sense? Or is better to create a static variable which
represents the default value copy and copy it?