Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Base
- {
- protected:
- Base()
- {}
- public:
- virtual void initialize()
- {}
- template<typename D, typename... Ts>
- static std::shared_ptr<D> create(Ts... args)
- {
- auto d = std::shared_ptr<D>(new D(args...));
- d->initialize();
- return d;
- }
- };
- class Derived : public Base
- {
- private:
- int value_;
- protected:
- public:
- Derived(int v) : value_(v)
- {}
- void initialize() override
- {
- //Do something with value_
- }
- };
- int main()
- {
- auto derived = Base::create<Derived>(42);
- // etc.
- return 0;
- }
Add Comment
Please, Sign In to add comment