Consider the following code:
#include <memory>
class A {};
class B : public A {};
void func( std::shared_ptr<A> ptr )
{
}
int main( int argc, char* argv[] )
{
func( std::shared_ptr<A>( new B ) );
}
The syntax std::shared_ptr<A>( new B )
requires A
class to be specified. It's a pain if the class is in a namespace and it makes code too verbose when it actually does not need to.
Is there no STL template function that would make the syntax lighter and have A
be deduced automatically?
I was thinking of something like: func( std::make_shared( new B ) )
but that's not what std::make_shared
is meant for.
I mean, there's the same for pair
, you can use std::make_pair
without having to specify what are the first/second pair types, ther are automatically deduced. Is there not "equivalent" for shared_ptr
?