managed pointers for CC

Hi there I was making a copy constructor for a LinkedQueue class and it compiles but I think there is something mixed up in it, please let me know if you see an error.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
template<class ItemType>
LinkedQueue<ItemType>::LinkedQueue(const LinkedQueue& aQueue)
{
	std::shared_ptr<Node<ItemType>>origChainPtr = aQueue.frontPtr;
	if (origChainPtr == nullptr)
	{
		frontPtr = nullptr;
		backPtr = nullptr;
	}
	else
	{
		frontPtr = make_shared<Node<ItemType>>();
		frontPtr->setItem(origChainPtr->getItem());

		shared_ptr<Node<ItemType>>newChainPtr = frontPtr;
		origChainPtr = origChainPtr->getNext();

		while (origChainPtr != nullptr)
		{
			ItemType nextItem = origChainPtr->getItem(); 

			std::shared_ptr<Node<ItemType>> newNodePtr = make_shared<Node<ItemType>>(nextItem); 

			newChainPtr->setNext(newNodePtr); 

			newChainPtr = newChainPtr->getNext(); 

			origChainPtr = origChainPtr->getNext(); 

		}
		backPtr = newChainPtr;
		newChainPtr->setNext(nullptr); 
		
	}
}

It uses a node class as you can see. Thanks!
Last edited on
> but I think there is something mixed up in it
¿what do you mean?

> It uses a node class as you can see.
sure, but I don't see how the node class is implemented.


you probably have an `insert()' method, might as well use it.
Last edited on
Topic archived. No new replies allowed.