Search code examples
c++inheritanceboostboost-propertytree

Adding static member variable to third-party class


I'm using Boost.Property_Tree for a project and I want to add a small bit of functionality to it. I want to add a "fromFile" static member variable that will figure out the file type and then use the proper parser. In my project, this is currently how I've got it.

typedef boost::property_tree::ptree ConfigNode;

Then I have another class called ConfigLoader that I've been using to load the file. I want to add the one function to a ConfigNode class though. I need the compiler to treat ConfigNode as if it were a boost::property_tree, but I want to add one static function. Is there a way to do this?


Solution

  • Nope. There's no clean way to do this.

    You have two options:

    1. Declare your functions and variables outside of the class completely (e.g. in another class or global in some namespace).
    2. Subclass boost::property_tree, adding your static member(s).