當您將一個unique_ptr複製到另一個時,正在閱讀有關智能指針的更多信息,並遇到了構造函數被刪除的概念。這個概念到底是什麼? #include<iostream>
#include<memory>
class Person {
public:
int e;
Person(int e) : e(e) { }
};
int main() {
st
class A{
public:
A():p(nullptr){};
private:
std::unique_ptr<B> p; // B is some class
};
當A的對象超出範圍時,將自動刪除佔用內存空間的內存空間,該內存空間消耗的內存空間爲p。 我們是否應該像下面那樣顯式編寫析構函數? ~A(){
delete p;
我讀這個答案霍華德Hinnant(Is std::unique_ptr<T> required to know the full definition of T?),然後這個答案(How is a template instantiated?),我只是在想。如果你有像這樣 class Something {
Something();
~Something();
cla