I have this function, which should generate different derivatives of objs and return as unique_ptr<base> :
class base {}; // contains pure functions. class derived1 {}; // reifies that pure iface. class derived2 {}; // reifies that pure iface. unique_ptr<base> factory::load(int param) { switch (param) { case PARAM_MAIN: return new derived1(); // return std::move(new derived1()); case PARAM_2: return new derived2(); case ...: return new derived...(); } }
I cannot do this even using std :: move. (Also used dynamic_cast, but may have done it wrong).
This is the error I get: (gcc (GCC) 4.8.1 20130725 (preerelease) on ArchLinux)
could not convert '(std::shared_ptr<base::model>((*(const std::shared_ptr<base::model>*)(& associatedModel))), (operator new(48ul), (<statement>, ((derived1*)<anonymous>))))' from 'derived1*' to 'std::unique_ptr<base>' associatedModel));
I hope I clearly understood what I want to do.
How should I do it? Thanks.
source share