hyperrealm / libconfig

C/C++ library for processing configuration files
https://hyperrealm.github.io/libconfig/
GNU Lesser General Public License v2.1
1.1k stars 359 forks source link

How do I use libconfig::Setting as a member variable? #198

Closed keineahnung2345 closed 2 years ago

keineahnung2345 commented 2 years ago

I've tried:

// declare the private member variable
libconfig::Setting setting;

// in constructor, setup it
const libconfig::Setting& root = cfg.getRoot();
setting = root["x"]["y"]; //operator= is inaccessible

and also:

// declare the private member variable
libconfig::Setting* setting;

// in constructor, setup it
const libconfig::Setting& root = cfg.getRoot();
setting = new libconfig::Setting(root["x"]["y"]); // Setting(const Setting& other) is inaccessible

Both method fail, so how do I use libconfig::Setting as a member variable?

hyperrealm commented 2 years ago

The Setting object is not meant to be used that way. You should copy the value of the setting into a variable of the appropriate type, and use that as your member variable.

keineahnung2345 commented 2 years ago

OK, thanks.