vector and constructors
Hi,
I have a class C, and want to have a vector like
vector thecs; (well, sorry for forgetting that this is HTML)
vector<C> thecs;
And C has a constructor that requires parameters. When I insert a new element using
thecs.push_back(C(param));
One instance of C is created, passed to push_back() as parameter and destroyed after push_back() retuns. The vector creates another copy of C and stores it, is that right?
So if it is true, is there any way not to create a temporary class when inserting a new instance to my vector? I want the vector to handle my instances, I don't want to use dynamic memory in this particular example.
Thanks.
I have a class C, and want to have a vector like
vector<C> thecs;
And C has a constructor that requires parameters. When I insert a new element using
thecs.push_back(C(param));
One instance of C is created, passed to push_back() as parameter and destroyed after push_back() retuns. The vector creates another copy of C and stores it, is that right?
So if it is true, is there any way not to create a temporary class when inserting a new instance to my vector? I want the vector to handle my instances, I don't want to use dynamic memory in this particular example.
Thanks.
