Relevant header definitions are as:
class XMLChain
{
private:
Segment root;
std::vector<XMLOpen*> chain;
Segment * immediate;
std::vector<XMLOpen> openers;
The function in question is:
void XMLChain::open(std::string tag)
{
Segment * last_immediate = immediate;
openers.push_back( XMLOpen ( tag ) );
XMLOpen * cast_immediate = &(openers.back());
(*last_immediate).setNext( cast_immediate );
immediate = cast_immediate;
return;
}
Considerations are:
- XMLOpen is a subclass of Segment
My problem is:
Calling XMLChain::open one time has the desired effect; that is;
- the 'immediate' pointer is derived (which references the last Segment of any type to be created into an XMLChain).
- an XMLOpen segment is created and placed to the back of the 'openers' vector.
- the address of the backend of the openers vector is sent to the reference of the immediate pointer via 'setNext()'; this means that the last Segment sees the new XMLOpen Segment as the 'next' part of its output sequence.
- a pointer to the new XMLOpen address replaces the immediate pointer; for next time
However. Calling XMLChain::open again causes the last XMLOpen Segment to be treated as if it were an unextended Segment when I check the output (Segments are like a linked list, with each subclass having a specialized constructor and std::string output() function). The same happens on the next and subsequent attempts to call XMLChain::open; that is, the 'root' Segment has a line of Segments down to the last added Segment subclass, which is treated as if it were the correct Segment subclass.
Why?