Question: C++ Error. I'm having trouble with a pointer. I keep getting the error Thread 1: EXC_BAD_ACCESS (code=1, address=0x18) The objective of the assignment is to

C++ Error. I'm having trouble with a pointer. I keep getting the error "Thread 1: EXC_BAD_ACCESS (code=1, address=0x18)"

The objective of the assignment is to revise the public method add in class template LinkedBag so that the new node is inserted at the end of the linked chain instead of at the beginning.

This is the code I have:

linkedBag-driver.cpp

C++ Error. I'm having trouble with a pointer. I keep getting the

BagInterface.hpp

error "Thread 1: EXC_BAD_ACCESS (code=1, address=0x18)" The objective of the assignment isto revise the public method add in class template LinkedBag so that

LinkedBag.hpp

the new node is inserted at the end of the linked chaininstead of at the beginning. This is the code I have: linkedBag-driver.cpp

Node.hpp

BagInterface.hpp LinkedBag.hpp Node.hpp int main) LinkedBag bag; cout * nextNodePtr); void setItem(const ItemType& anItem); void setNext (Node* nextNodePtr); ItemType getItem() const Node template

int main) LinkedBag bag; cout * nextNodePtr); void setItem (const ItemType& anItem); void setNext (Node* nextNodePtr); ItemType getItem() const Node template Node: :Node() : next(nullptr) > // end default constructor template Node:: Node (const ItemType& anItem) : item(anItem), next (nullptr) > // end constructor template Node:Node (const ItemType& anItem, Node* nextNodePtr): item (anItem), next (nextNodePtr) > // end constructor template void Node::setItem (const ItemType& anItem) item = anItem; l // end setItem template void Node: :setNext (Node ItemType Node: :getItem) const return item; // end getItem template Node* Node::getNext) const return nexti / end getNext #endif #ifndef LINKED BAG #define LINKEDBAG - #include #include "BagInterface.hpp.. "Node.hpp.. template class LinkedBag : public BagInterface private: Node* headPtr; // Pointer to first node int itemCount; /Current count of bag items // Returns either a pointer to the node containing a given entry // or the null pointer if the entry is not in the bag. Node* getPointerTo (const ItemType& target) const; public: LinkedBag); LinkedBag (const LinkedBag& aBag) I7 Copy constructor virtual LinkedBag(); int getCurrentSize) const; bool isEmpty) const; bool add(const ItemType& newEntry); bool remove (const ItemType& anEntry); void clear) bool contains (const ItemType& anEntry) const; int getFrequencyOf (const ItemType& anEntry) const; std: : vector toVector() const; bool remove ) // Destructor should be virtual template bool LinkedBag: :add(const ItemType& newEntry) / /New Node Node* nextNodePtr = new Node(); //Set item nextNodePtr->setItem (newEntry); //Set next item nextNodePtr->setNext (nullptr); //If bag is empty if (isEmpty )) headPtr nextNodePtr; //If bag is not empty else //Find last node Node lastNodePtrnew Node ItemType> ); for (int n-1; n getNext); lastNodePtr->setNext(nextNodePtr); Thread 1: EXC_BAD_ACCESS (code-1, address 0x18) itemCount++ return true; l // end add #ifndef NODE #define NODE template class Node private: item; // A data item ItemType Node* nextNodePtr); void setItem (const ItemType& anItem) void setNext (Node*nextNodePtr); ItemType getItem() const Node* getNext) const //#include template Node: :Node) : next (nullptr) / end default constructor template Node::Node (const ItemType& anItem) : item(anItem), next (nullptr) h // end constructor template Node: :Node (const ItemType& anItem, Node* nextNodePtr): item(anItem), next(nextNodePtr) > // end constructor template void Node:setItem(const ItemType& anItem) item- anItem; / end setItem template void NodesetNext (NodenextNodePtr) next nextNodePtr; Thread 1: EXC_BAD_ACCESS (code-1, address 0x18) > // end setNext template ItemType Node::getItem) const return item; // end getItem template Node: :getNext) const return next; // end getNext #endif

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!