Hello, I have a problem with lists. Basically I would like to create 3 pointers to bunny objects ( lines 5 to 7 ) and place them in a list. Then I would like to pass the list to the function called AnyMutants() (line 9 ) .This function simply steps through the list and perfoms a IsMutant() function on each object. Then return the Boolean result to answer when it finds an occurance when this true. However , I’m really struggling as i want to pass the list as a reference but it is created as a list of pointers to objects???,. I get an error at line 18, saying the operators don’t match the operands?. see code below.
IsMutant() is obviously a member function of mutantType
It should be -> bool anyMutants(const list< mutantType*> & tempList)
(2) Since you pass your list by a const reference, you need a const_iterator ;)
Do it like this -> std::list<mutantType*>::const_iterator i;
Also, make sure your Ismutant function is const correct.
EDIT: Though, now that I look at it again, if what you want is to check if there are any mutants, you should do it in a slightly different way... If you find at least one mutant, return true, and if you find no mutants, return false. The way you do it here, you return false when you find the first non-mutant bunny; that's not what you want.
EDIT 2: I just noticed this. You say 'IsMutant' and in your code you write 'Ismutant'. These two are not the same.
Thanks for that, i've made a few changes based on what you sugguested.see below. However i'm getting and error at line 20 with "no operator matching these operands".It's highlighting the asterix for the pointer again!!