Reputation: 87
Say I want to declare some private class member variables in a class for a doubly linked list and am trying to do something like:
DoublyLinkedList<ShippingStatus> package;
DoublyLinkedListIterator<ShippingStatus> ship(&package);
I realize that the second line is not possible, but is there any way to declare the ship
variable by passing in the linked list values as reference? I have done the second line within other functions successfully, but this would mean ship
would be reset each time these functions are called, and I want the position of my iterator saved "globally" as the program runs. This is what the constructor for the iterator class looks like
DoublyLinkedListIterator(DoublyLinkedList<ELT>* list) {
assert(nullptr != list);
_location = list->_header->next();
}
I can provide any further functions if needed.
Upvotes: 1
Views: 229
Reputation: 6240
Perhaps you could use member initializer list:
template <typename ShippingStatus>
class MyClass
{
DoublyLinkedList<ShippingStatus> package;
DoublyLinkedListIterator<ShippingStatus> ship;
public:
MyClass(DoublyLinkedList<ShippingStatus> package) : package{ package }, ship{ &(this->package) } {}
};
Upvotes: 1