Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Vectors using user-defned classes

Status
Not open for further replies.

skullay

Programmer
Nov 26, 2003
2
HK
Do you call on your class's constructor when using the push_back() vector funtion?

example:

myVector.push_back( classConstructor( arg1, arg2, arg3) );

would this be correct?
 
when pasing a parameter is used the copy contructor. So for a right passing of parameter implement
classConstructor( classConstructor&) but when calling the function you can use any constructor, however after this contstructor anyway will be called copy contructor.

Ion Filipski
1c.bmp
 
thanks!

one last question.

does the vector class come with a function that can delete a particular element.

example:

vector<int> myVector;

myVector.push_back(1);
myVector.push_back(2);
myVector.push_back(3);

how would i delete the 2 (which corresponds to myVector[1])from myVector?

is there a myVector.delete( element# ) included in the vector class?
 
use remove and erase. Remove will move elements from the right side of element to n position in the left, but erase will delete physically elements between iterators you specify. Read STL manual for more information.

Ion Filipski
1c.bmp
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top