We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 1136c58 commit 963dd9aCopy full SHA for 963dd9a
shared_ptr.cpp
@@ -0,0 +1,29 @@
1
+#include <iostream>
2
+#include <memory>
3
+
4
+class Rectangle {
5
+public:
6
+ Rectangle(int w, int h) : width(w), height(h) {}
7
+ ~Rectangle() { std::cout << "Rectangle destructor" << std::endl; }
8
+ int getArea() { return width * height; }
9
+private:
10
+ int width;
11
+ int height;
12
+};
13
14
+int main(){
15
+ Rectangle* rectp = new Rectangle(5, 3);
16
+ std::shared_ptr<Rectangle> rectsp1(rectp);
17
+ std::shared_ptr<Rectangle> rectsp2(rectp);
18
+ //rectsp1.reset(rectp);
19
+ std::cout << rectsp1->getArea() << std::endl;
20
+ return 0;
21
+}
22
23
+/*
24
+15
25
+Rectangle destructor
26
27
+free(): double free detected in tcache 2
28
+中止 (核心已傾印)
29
+*/
0 commit comments