私は次のようにstd::shared_ptr
new
とオペレータを定義しようとしているとのstd :: shared_ptrを定義するとき:エラーは、new演算子
: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();
#include <memory>
struct A {
};
int main() {
std::shared_ptr<A> ptr = new A();
return 0;
}
を、私は、次のコンパイル時のエラーを得ました
とにかく、次は間違いなく動作します:
std::shared_ptr<A> ptr{new A()};
があなたの誰もがkのんなぜこれが起こるのでしょうか?
好ましいのは、いや、それは代入ではありません。 –
@ LightnessRacesinOrbitええ、あなたは正しいです。私はその部分を改めた。 – Hayt