I'm having issue with calling a method with l-value of an abstract class. The class definition is:
class SimulatorSequenceItemBase {
public:
SimulatorSequenceItemBase();
virtual ~SimulatorSequenceItemBase();
virtual uint32_t GetResult(uint32_t p_nSite) = 0;
virtual bool MoveNext(SimulatorSequenceItemBase& p_rNext) = 0;
}
SimulatorSequenceItemBase has multiple sub classes. There are sequences (for loops) and items for within the for loop.
I want to loop through the sequence and count the steps, using:
uint32_t nI = 0;
SimulatorSequenceItemBase root = forSeq; // forSeq is an instance of a subclass of SimulatorSequenceItemBase
while(root.MoveNext(root))
{
++nI;
std::cout << root.GetResult(0);
}
The root initally references to the root, and on every call to MoveNext, the reference should be adjusted to the next element.
The code mentioned above does not work, because root cannot be allocated, as the type of root is abstract. But if I'd make root a pointer, then the value cannot be altered in MoveNext.
How can I fix this? It's OK to change any code, but the idea should stay the same.