if I have for example some class Base and derived from it Derived
Also I have some list of shared pointers:
list<shared_ptr<Base> > list
I create shared pointer:
line 5 shared_ptr<Derived> ptr(new Derived(//some constructor));
my question is, can I do something like this:
list.push_back(ptr);
if Yes, can somebody explain why can I recieve an error (I receive this on the line 5)
no matching function for call to //here It writes me my constructor to Derived
thanks in advance for any help
Yes – your problem has nothing to do with inheritance or smart pointers – you simply don’t have the constructor declared you are trying to use.
A simple example that reproduces the error is:
Which gives you:
You fix that by either constructing the instance differently or by adding the missing constructor: