I am trying to define a std::shared_ptr with new operator in the following way:
#include <memory>
struct A {
};
int main() {
std::shared_ptr<A> ptr = new A();
return 0;
}
but I obtained the following compile-time error:
main.cpp: In function 'int main()':
main.cpp:8:30: error: conversion from 'A*' to non-scalar type 'std::shared_ptr' requested std::shared_ptr ptr = new A();
Anyway, the following definitely works:
std::shared_ptr<A> ptr{new A()};
Does anyone of you know why this happens?