I have a pointer which sliced, but I don't exactly know where and why. There are two lines of code which I think could lead to splicing:
The creation of a unique pointer:
map.insert(make_pair("ChildA", unique_ptr<Base>(new ChildA())));
and the returning of raw pointer from my unique pointer:
return map["ChildA"].get();
note that:
- Class ChildA inherits Base
- Base has a virtual destructor
the map in the example above is of type:
map<string, unique_ptr<Base> >
Does splicing occur in either of the lines of code stated above? Is there an easy way to avoid where it does?