C
Christof Krueger
Hello,
I'm quite new to C++ and have some base C knowledge. So I know how to
solve a given problem, by I sometimes tend to fall back to C. That is
what I want to avoid in my current project. Therefore I have the
following question:
I maintain a list of objects that are created. There is some information
that is logically related to each instance. I encapulate this in a
struct like this:
struct myListEntry {
myObject entry;
int relatedData;
}
What is the ideal way to implement adding another object to the vector?
(myVector has type vector<myListEntry> in this example)
Should I use malloc to reserve memory for my struct?
Should I do the following?
...
myListEntry newEntry;
newEntry.entry = something;
newEntry.relatedData = something_else;
myVector.push_back(newEntry);
...
Or is there another preferred way?
Regards,
Christof Krueger
I'm quite new to C++ and have some base C knowledge. So I know how to
solve a given problem, by I sometimes tend to fall back to C. That is
what I want to avoid in my current project. Therefore I have the
following question:
I maintain a list of objects that are created. There is some information
that is logically related to each instance. I encapulate this in a
struct like this:
struct myListEntry {
myObject entry;
int relatedData;
}
What is the ideal way to implement adding another object to the vector?
(myVector has type vector<myListEntry> in this example)
Should I use malloc to reserve memory for my struct?
Should I do the following?
...
myListEntry newEntry;
newEntry.entry = something;
newEntry.relatedData = something_else;
myVector.push_back(newEntry);
...
Or is there another preferred way?
Regards,
Christof Krueger