I have a list of type Instruction*. Instruction is a class that I made. This class has a function called execute().
I create a list of Instruction*
list<Instruction*> instList;
I create an Instruction*
Instruction* instPtr;
instPtr = new Instruction("test",10);
If I call
instPtr.execute();
the function will be executed correctly, however if I store instPtr in the instList I cannot call the execute() function anymore from the list.
//add to list
instList.push_back(instPtr);
//create iterator for list
list<Instruction*>::iterator p = instList.begin();
//now p should be the first element in the list
//if I try to call execute() function it will not work
p -> execute();
I get the following error:
error: request for member ‘execute’ in ‘* p.std::_List_iterator<_Tp>::operator-> [with _Tp = Instruction*]()’, which is of non-class type ‘Instruction*’