Question
in c++ i have the following classes class stringHolder{ node *head; public: stringHolder(); void add(string str); } class node{ private: node *next; string str; public:
in c++ i have the following classes
class stringHolder{
node *head;
public:
stringHolder();
void add(string str);
}
class node{
private:
node *next;
string str;
public:
node();
}
how would i write a private function in the string holder class that could take in head->next modify it so that if head->next is called again it maintains that modification?
for example, if i added the following private function to be called from the add function in the stringHolder class
void string_Holder::update(node *ptr, string _str){
ptr->str = _str;
}
and then once i'm back in the add function if i access head->next it shows that it's str variable has been modified?
so like
void stringHolder::add(string str){
node *temp = head->next;
if(temp==NULL){
update(head->next, "hello");
}
std::cout<<"head->next->str =" << head->next->str << std::endl;
and have it display hello?
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started