I am not sure whether it is the right way or am I deleting the memory properly. I have seen here some custom implementation of linked list, I want to do it simple way. Can anyone please suggest is it right or not? Should I use shared ptr, even if I do it, how to implement it correctly.
.hpp
class Camera {
Camera()
{}
~Camera()
{}
}; typedef struct Node *NodePtr;
// Now declare the structure type itself
struct Node
{
Camera_ x;
NodePtr next;
};
.cpp
NodePtr head = NULL;
NodePtr* ptr = &head;
for (int n = 0; n<n1; ++n)
{
*ptr = new Node;
(*ptr)->x = Camera(); //storing camera objects
ptr = &(*ptr)->next;
}
// terminate the list.
*ptr = NULL;
// walk the list,
for (NodePtr cp = head; cp->next != NULL; cp = cp->next)
{
// doing camera functions
}
NodePtr
are an abomination: They just add more mental overhead. \$\endgroup\$cp != NULL
instead ofcp->next != NULL
. \$\endgroup\$