I am new to the C ++ standard library. I want to use std :: list. I know that if I create a list myself, instead of using stl, I have to allocate memory for a new object and then add it to the list.
list of c-style class A:
A *ptrA = new A();
ptrA->setElement(value);
ptrA->next = null;
currentPositionMyCstyleList->next = ptrA;
ptrA->prev = currentPositionMyCstyleList;
If I use stl, do I need a "new" object? Does push_back () a "new" object before to add to std :: list in C ++?
Is the code below correct?
A aObj(value);
listA.push_back(aObj);
Will the aObj value be released in the code below:
funcAddToList() {
A aObj(value);
listA.push_back(aObj);
}
funcDispList() {
}
What does push_back () actually do?
I am still confused after reading stl_list.h_push_back () , _ M_insert , _ M_create_node
Thank you for your time.