#include <utility>
#include <memory>
#include <string>
#include <iostream>
class Base {
public:
Base() { std::cout << "Base() constructor" << std::endl; }
virtual ~Base() { std::cout << "~Base() destructor" << std::endl; }
};
class Derived : public Base {
public:
Derived() { std::cout << "Derived() constructor" << std::endl; }
~Derived() { std::cout << "~Derived() destructor" << std::endl; }
};
template <typename T, typename... Args>
std::shared_ptr<T> make_shared_2(Args&&... rest)
{
return std::shared_ptr<T>(new T(std::forward<Args>(rest)...));
}
int main()
{
std::shared_ptr<std::string> sps = make_shared_2<std::string>(10, 'c');
std::cout << *sps << std::endl;
std::shared_ptr<Base> sps2 = make_shared_2<Derived>();
return 0;
}