So after working on my last question, I boiled it down to this:
I need to add an unknown number user-defined classes (object_c
) to a boost::intrusive::list
. The classes have const
members in them. All I need to do to push them to the list
is to construct them and then have them persist, they automatically add themselves.
The code in question is basically
for (unsigned i = 0; i < json_objects.count(); ++i) {
ctor_data = read(json_objects[i]);
// construct object here
}
What I've tried:
malloc
ing an array of objects, then filling them in: Doesn't work, because I haveconst
members.static object_c *json_input = (object_c*) malloc(json_objects.size() * sizeof(object_c)); ... json_input[i](ctor_data); //error: no match for call to (object_c) (ctor_data&)
Making a pointer: This doesn't work, functions don't work properly with it, and it doesn't get destructed
new object_c(ctor_data);
Pushing the object back to an
std::vector
: This doesn't work, boost rants for dozens of lines when I try (output here)vector_of_objects.push_back(object_c(ctor_data));
Just declaring the darn thing: Obviously doesn't work, goes out of scope immediately (dur)
object_c(ctor_data);
I'm sure there is an easy way to do this. Anyone have any ideas? I've been at this problem for most of the weekend.