Deep copy or Reference in map?

Hello everyone,

I am a bit confused of this:

1
2
3
4
5
6
7
8
9
10
map<string,XMLDocument> docs;

XMLDocument doc;

       
if (doc.LoadFile(ent->d_name) != XML_SUCCESS){
throw "Fail to load config file!";
}

_docs.insert(_docs.begin(), pair<string,XMLDocument>(getPath(),doc));


In the insert line, I am not sure if a deep copy of doc is made or it's only a reference? Should I pass &doc instead?

Regards

It's a copy.

Whether or not it's a deep copy depends on the implementation of XMLDocument. But it's probably safe to assume it's a deep copy.

EDIT:

And no, you should not pass &doc because that would give you a XMLDocument* and not an XMLDocument like your map requires.
Last edited on
Topic archived. No new replies allowed.