K
kelvSYC
My mind seems to be having a brain freeze. Anyways, here goes:
I have a function that constructs an A from some other data, like so:
A foo();
and I would like to add something returned from it into a
std::vector<A*> elsewhere in my code. To do so, do I just do so, like
std::vector<A*> list;
list.push_back(&foo());
Or do I have to change foo() so that it returns a pointer? If so, (and
here's where my knowledge of C++ is shaky), can I only return something
that's allocated using new? If so, will that item be automatically
deleted once the vector is deallocated (or would I have to write
something extra?
I have a function that constructs an A from some other data, like so:
A foo();
and I would like to add something returned from it into a
std::vector<A*> elsewhere in my code. To do so, do I just do so, like
std::vector<A*> list;
list.push_back(&foo());
Or do I have to change foo() so that it returns a pointer? If so, (and
here's where my knowledge of C++ is shaky), can I only return something
that's allocated using new? If so, will that item be automatically
deleted once the vector is deallocated (or would I have to write
something extra?