I am trying to define an operator std::shared_ptrwith an operator newas follows:
#include <memory>
struct A {
};
int main() {
std::shared_ptr<A> ptr = new A();
return 0;
}
but I got the following compile time error:
main.cpp: In the function 'int main ()':
main.cpp: 8:30: error: conversion from "A *" to the non-scalar type "std :: shared_ptr" requested by std :: shared_ptr ptr = new A ();
In any case, the following definitely works:
std::shared_ptr<A> ptr{new A()};
Do any of you know why this is happening?
source
share