boost::excessive_syntax
Apologies to the majority of people who have no idea what this is about.
class YourBrain
{
public:
     YourBrain();
     virtual ~YourBrain();
Â
     YourBrain* Get()
     {
           return this;
     }
Â
     static YourBrain* Create()
     {
           return new YourBrain();
     }
};
Â
class YourBrainDerived : public YourBrain
{
public:
     YourBrainDerived *Get()
     {
           return this;
     }
Â
     static YourBrainDerived* Create()
     {
           return new YourBrainDerived();
     }
};
Â
std::vector<YourBrain *> GetListOfYourBrain()
{
     std::vector<YourBrain *> oList;
     oList.push_back(YourBrain::Create());
     oList.push_back(YourBrainDerived::Create());
     return oList;
}
Â
#include <boost/shared_ptr.hpp>
#include <boost/enable_shared_from_this.hpp>
Â
class YourBrainOnSharedPointers : public boost::enable_shared_from_this<YourBrainOnSharedPointers>
{
public:
     YourBrainOnSharedPointers();
     virtual ~YourBrainOnSharedPointers();
Â
     boost::shared_ptr<YourBrainOnSharedPointers> Get()
     {
           return shared_from_this();
     }
Â
     static boost::shared_ptr<YourBrainOnSharedPointers> Create()
     {
           return boost::shared_ptr<YourBrainOnSharedPointers>(new YourBrainOnSharedPointers());
     }
};
Â
class YourBrainOnSharedPointersDerived : public YourBrainOnSharedPointers
{
public:
     boost::shared_ptr<YourBrainOnSharedPointersDerived> Get()
     {
           return boost::dynamic_pointer_cast<YourBrainOnSharedPointersDerived>(shared_from_this());
     }
Â
     static boost::shared_ptr<YourBrainOnSharedPointersDerived> Create()
     {
           return boost::shared_ptr<YourBrainOnSharedPointersDerived>(new YourBrainOnSharedPointersDerived());
     }
};
Â
std::vector<boost::shared_ptr<YourBrainOnSharedPointers> > GetListOfYourBrainOnSharedPointers()
{
     std::vector<boost::shared_ptr<YourBrainOnSharedPointers>> oList;
     oList.push_back(boost::shared_ptr<YourBrainOnSharedPointers>(YourBrainOnSharedPointers::Create()));
     oList.push_back(boost::shared_ptr<YourBrainOnSharedPointersDerived>(YourBrainOnSharedPointersDerived::Create()));
     return oList;
}
Any Questions?
(If the post just looks like an unreadable pile of punctuation, that's kind of the point).