比方說,我有東西,看起來像這樣: struct foo {
~foo() = delete;
}
而且我們說,我以後動態分配foo類型的對象: foo *f = new foo;
這是罰款;我認爲合成的默認構造函數用於構造由f表示的對象,但是: foo f2;
給我一個錯誤: Attempt to use a deleted function 因此,如何通過f表示的對象,如
對於下面的代碼 struct MyInt {
MyInt() {
std::cout << "I am the constructor for " << val << "\n";
}
~MyInt() {
std::cout << "I am the destructor for " << val << "\n";
}
in