A nicer way to avoid pointers

I have this function:

1
2
3
4
5
6
7
8
9
10
11
12
13
Node Device::ToXML() { ... }
void Node::AppendChild( Node& n ) { ... }

Node Calibrator::ToXML()
{
  Node e;
  e.CreateElement( CALIBRATOR_NAME );

  for ( Device dev : m_devices )
    e.AppendChild( dev.ToXML() ); // <-- Problem

  return e;
}



I'm starting to think that I can't avoid pointers here. I need a permanent object for the AppendChild() function, but the result of dev.ToXML() is a local object. Node is from a 3rd party library (which wraps RapidXML) that I'm not going to be changing. Cleaning up dynamic memory would be messy here and so I'd like to avoid pointers if possible. Does anyone have a good suggestion? I can change the return type of dev.ToXML() without any issues.
Last edited on
Topic archived. No new replies allowed.