It keeps on saying "function contains is never used". I've never posted before, so if you have advice on how I can get my point across better please let me know.
[Edit] I'm trying to post only code that I wrote myself. I wrote these 3 functions, and only the first one works:
This is what's in the CPP file:
template<class ItemType>
ItemType LinkedList<ItemType>::replace(int position, const ItemType& newEntry)
{
std::cout << "replacing at position " << position << " with " << newEntry << std::endl;
Node<ItemType>* curPtr =this->getNodeAt(position);
curPtr->setItem(newEntry);
return newEntry;
} // end replace
// TODO: LinkedList<ItemType>>::contains
template<class ItemType>
bool LinkedList<ItemType>::contains(const ItemType& entry)
{
for(int i = 0; i<this->getLength(); i++)
{
Node<ItemType>* curPtr = this->getNodeAt(i+1);
if(curPtr->getItem()==entry) {
return true;
}
}
return false;
}
// TODO: LinkedList<ItemType>>::containsRecursive
template<class ItemType>
bool LinkedList<ItemType>::containsRecursive(Node<ItemType>* node,const ItemType& entry){
if(node == nullptr){
return false;
}
if(node->getItem()==entry){
return true;
}
return containsRecusive(node->getNext(),entry);
}
and this is what's in the header
ItemType replace(int position, const ItemType& newEntry);
bool contains(const ItemType& entry);
bool containsRecursive(Node<ItemType>* node,const ItemType& entry);
and when I try to call it in the driver, it doesn't appear on the dropdown. Just the other functions in the program such as:
replace, remove, insert, getNodeAt, getEntry, getLength, clear, and isEmpty
and it basically says the function doesn't exist, when I call it in the driver with
listPtr->contains("hello"); //doesn't work, turns red
listPtr->replace(1,"hello"); //does work
listPtr->containsRecurssive(headPtr, "hello")//doesn't work, turns red
The contains is red, and it says, "No member named 'contains' in 'ListInterfacestd::basic_string<char>'"
And it still says in the .h and the .cpp file that "Function 'contains' is never used"
But all the other functions work fine.