I have a scenario where I use CRTP. pseudo code below;
template <typename T>
class Base {}
class Derived1 : Base < Derived1 > {}
class Derived2 : Base < Derived2 > {}
everything works fine EXCEPT when I introduce unique_ptr in to the loop. I want to have a unique_ptr to Base and elsewhere in the code use this to take ownership of either a Derived1 or Derived2 pointer.
// declaration - this is the problem - wont compile.
std::unique_ptr<Base> base_unique_ptr;
// cpp , elsewhere.
base_unique_ptr.reset(new Derived1());
or
base_unique_ptr.reset(new Derived2());
am I in trouble? I don't want to change the existing codes use of unique_ptr.
unique_ptr<
Aucun commentaire:
Enregistrer un commentaire