I'm attempting to make a configuration manager class, that may store arbitrary objects by std::string.

My beginning idea for my interface (abstract base class) was this (obviously this really is horribly incomplete)

class ConfigurationManager
{
public:
   static boost::shared_ptr<ConfigurationManager> create();

   template<typename T>
   virtual T getOption(const std::string& name) = 0;
};

However my compiler stated that template's can't be virtual(after which I recognized which i cannot have released templates anyways).

Internally I will be utilising boost::any's(virtually a runtime checked void*), however i don't want to reveal boost::any during my interface.

An amount be the easiest method to build a storage shed?

Create a protected virtual abstract function coming back boost::any, along with a non-virtual, non-abstract, public template function to cover it in the customers of the interface.

class ConfigurationManager {
protected:
    virtual boost::any getOptionProtected(const std::string& name) = 0;
public:
    static boost::shared_ptr<ConfigurationManager> create();
    template<typename T> T getOption(const std::string& name) {
        return boost::any_cast<T>(getOptionProtected(name));
    }
};

An alternate approach is always to pass the title from the derived type to ConfigurationManager:

template<typename Derived>
class ConfigurationManager
{
  public:
    static boost::shared_ptr<ConfigurationManager> create();

  template<typename T>
  T getOption(const std::string& name)
  {
    // call Derived::getOption
    return static_cast<Derived*>(this)->getOption(name);
  }
};

The derived type Foo would then be defined such as this:

class Foo : public ConfigurationManager<Foo>
{
  template<typename T>
  T getOption(const std::string& name)
  {
    // do something Foo-specific here
  }
};

The finish outcome is something such as an abstract virtual function. This idiom is known to because the curiously recurring template pattern.

I'm not sure what boost::any does for you personally, but in addition to that your (only, I believe) choices are either 1) Make ConfigurationManager a template class, or 2) make ConfigurationManager::getOption non-virtual but make use of a separate non-template virtual function (known as within getOption) that handles the functionality you would like inside your derived classes. You will find also variants on 2), for example together with a pointer for an object which identifies the intended functionality of (non-virtual) getOption. This object could be a clear case of a category that is itself a part of an inheritance hierarchy--the process pattern essentially. Appears more difficult though. So essentially I'm recommending

class ConfigurationManager
{
   public:
      ...
      template<typename T>
      getOption(...);
   private:
      virtual getOptionSpecial(...) = 0; //Called within getOption
};

The very best response to this SO thread is (simply) why I believe this really is virtually all you are able do.