У меня есть список типа Инструкция *. Инструкция это класс, который я сделал. В этом классе есть функция execute ().
Я создаю список инструкций *
list<Instruction*> instList;
Я создаю инструкцию *
Instruction* instPtr;
instPtr = new Instruction("test",10);
Если я позвоню
instPtr.execute();
функция будет выполнена правильно, однако, если я сохраню instPtr в instList, я больше не смогу вызвать функцию execute () из списка.
//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();
Я получаю следующую ошибку:
error: request for member ‘execute’ in ‘* p.std::_List_iterator<_Tp>::operator-> [with _Tp = Instruction*]()’, which is of non-class type ‘Instruction*’