Website Summary Files Commits Branches @commit @diff @stats
diff options
context:
space:
mode:
Commit953db6cd289e582a5e0009dd5ac115f72c4343ca (patch)
Author
 Angel Dimitriev <achi_d@abv.bg>
2020-03-15 21:44:23 +0200
Committer
 GitHub <noreply@github.com>
2020-03-15 21:44:23 +0200
Files9168711aee33ccb1e7ca80096464a43c1a49801a
Object-oriented_programming_FMI-953db6cd289e582a5e0009dd5ac115f72c4343ca.tar
Object-oriented_programming_FMI-953db6cd289e582a5e0009dd5ac115f72c4343ca.tar.gz
Object-oriented_programming_FMI-953db6cd289e582a5e0009dd5ac115f72c4343ca.zip
Parentb0198df841b42a3a8d92a865bfc4024a0d6e9d33 (diff)
Delete 1. auto_ptr.cpp
1 files changed, 0 insertions, 50 deletions
-rw-r--r--Smart_pointers/1. auto_ptr.cpp50
diff --git a/Smart_pointers/1. auto_ptr.cpp b/Smart_pointers/1. auto_ptr.cpp
deleted file mode 100644
index a28851b..0000000
--- a/Smart_pointers/1. auto_ptr.cpp
+++ /dev/null
@@ -1,50 +0,0 @@
-
-#include <iostream>
-#include <memory>
-
-using namespace std;
-
-class Test
-{
-public:
- Test()
- {
- cout << "Test()" << endl;
- }
- Test(const Test& other)
- {
- cout << "Copy constructor" << endl;
- }
- Test& operator=(const Test& other)
- {
- cout << "Assignment operator" << endl;
- }
- ~Test()
- {
- cout << "Detructor" << endl;
- }
-
-};
-int main()
-{
- {
- auto_ptr<Test> smart_pointer_1(new Test()); //Test()
-
- Test* obj = smart_pointer_1.get(); //От тук иматаме достъп до паметта, към която сочи пойнтера.
- //delete obj; // Това не трябва да се прави! smart_pointer_1 не знае, че паметта е освободена и ще се опита да я освободи, което ще доведе до грешка!
-
- } //Test (Паметта се освобождава сама)
-
- {
-
- auto_ptr<Test> smart_pointer_2(new Test());
-
- auto_ptr<Test> smart_pointer_3(smart_pointer_2);
-
- smart_pointer_2.get(); // Това ще даде NULL, защото smart_pointer_3 "открадна" обекта на smart_pointer_2
-
- }
-
-
- return 0;
-}