2

I'm using libconfig in C++. Removing the surrounding complexity, I have read in a configuration and changed some settings. Now I want to take a copy of that Config object and make independent changes to the original and the copy. How can I do that?

From the libconfig documentation:

Note that by design, neither of these classes provides a public copy constructor or assignment operator

So the C++ libconfig API doesn't provide a mechanism for copying directly, likely because it's a nontrivial operation involving memory allocation. However it also doesn't support writing out to a string, although it does support ingesting from a string. The only solution I can find is to write it out to a temporary file (or one opened with fmemopen) and then read it back in again.

Is there a better way? It doesn't need to be cross-platform or standards compliant, Centos x86-64 is fine.

Obiphil
  • 361
  • 1
  • 6
  • 17

0 Answers0