I have a class which is a list. One member function plist
(process list) has a pointer to a function for a parameter.
The idea is to process all the objects of the list with a member
function of an object in the list here is a code snipit of the plist function
currenntly the list holds objects of type plorg
// process entire list with some function pointed to
//passing by value pf a pointer to the function whos argument is
//passed by refrence. An object of type Item(a Plorg).
// is this the correct interpritation?
void List::plist(void (*pf)(Item &))
//invoke editing function of object type Item for every object on list
for (int i=0;int<=index;i++)
(*pf)(item[i]); // call function using pointer passing by refrence a Plorg (Item) object.
//Is this correct?
Here is a snipit in main passing a member function of Creature
ci=50;// contentment index
void Plorg::eat()// problem here should this be eat(Item & item)
// if so this would be a member function of Creature that could
accept another object type Plorg from the list
// its so weird i am confused
ci++; //change this to item.ci++ then ?
(a Plorg) to the list for processing of the list.
(All objects in the list are the same at the moment)
My question concerns the plist function.
case 'P': if (Clist.isempty())
cout << "list is empty\n";
// pass adress of member function to plist
Clist.plist(Creature.eat);// give list function to invoke
Here I paraphrase from C++ Primer plus.
At the moment the function parameter's return type is void,
and pf points to a function that takes a refrence to an Item
argument, where item is the type of items in the list(plorgs).
Is what i am trying considered bad programming. I am confused
and not sure wtf I am doing could someone please help.