Hello Everyone - I'm sorry if iasking a repeat question but i've searched the forums and cant find out what's going wrong.

I am writing a program that has a pure virtual base animal class that has three subclasses - Cow, Chicken and Sheep.

Objects of the three types are created and stored in an STL list of type Animal but to avoid slicing problems instead of storing the actual animal in the list its an Animal*.

In my Animal base class I have a member function passTime() that increments the int age of the animal object be it a chicken/cow or sheep.

I have a method in my farm class (which stores the list of animals) also called passTime and this method iterates through the list of animals and executes the Animal passTime function on each of the objects.

However i'm getting C2440 and C2228 errors. I think it's something to do with the iterator and casting but i'm new to c++ and it's confusing me

Here is the function in question

void Farm::passTime()
{	
	list<Animal*>::iterator it;

	for(it = farmAnimals.begin(); it != farmAnimals.end(); it++)
	{
		Animal *x = &it;
		&x.Animal::passTime();		
	}
}

it is a pointer Animal *x = *it; x->passTime();

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.