Until now I have had a function that was getting an argument of type IArg
and I could do the following:
struct IArg
{
};
struct Arg : IArg
{
};
void f (IArg* arg)
{
// do something
}
f(new Arg);
Now when I got this:
void f (std::shared_ptr<IArg> arg)
{
// do something
}
Why it works again with
f(std::make_shared<Arg>());
std::shared_ptr<A>
and std::shared_ptr<B>
are different types even if A
and B
are related, right?
A std::shared_ptr<T>
is implicitly constructible from a std::shared_ptr<U>
if and only if a U *
is implicitly convertible to a T *
. See the constructor overload (9) on cppreference.com
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With