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

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!