Website Summary Files Commits Branches @commit @diff @stats
diff options
context:
space:
mode:
Commit95b972aba7401735425ee96518a42f17d0eca050 (patch)
Author
 Angel Dimitriev <angel_dimitriev@abv.bg>
2022-04-05 20:33:43 +0300
Committer
 GitHub <noreply@github.com>
2022-04-05 20:33:43 +0300
Files9a740ef5fc4cb48867aa6ce0738570c4019a2a19
Object-oriented_programming_FMI-95b972aba7401735425ee96518a42f17d0eca050.tar
Object-oriented_programming_FMI-95b972aba7401735425ee96518a42f17d0eca050.tar.gz
Object-oriented_programming_FMI-95b972aba7401735425ee96518a42f17d0eca050.zip
Parentde1b847ae63f6df5ce55cdead0396a2c863fab5b (diff)
Update README.md
1 files changed, 41 insertions, 21 deletions
-rw-r--r--Sem. 06/README.md62
diff --git a/Sem. 06/README.md b/Sem. 06/README.md
index c6ebcd7..86eafb6 100644
--- a/Sem. 06/README.md
+++ b/Sem. 06/README.md
@@ -17,44 +17,64 @@
**Забележка:** Копиращият конструктор създава нов обект, а оператор= модифицира вече съществуващ такъв!
-### Пример с копиращ конструктор.
+ ```c++
-```c++
#include <iostream>
-struct A
+using namespace std;
+
+struct Test
{
- A(int a)
+
+ Test()
{
- std::cout << "Constructor with one int parameter of A" << std::endl;
+ cout << "Default constructor" <<endl;
}
- A(const A& other)
+ Test(const Test& other)
{
- std::cout << "Copy constructor of A" << std::endl;
+ cout << "Copy constructor" <<endl;
}
- ~A()
+ Test& operator=(const Test& other)
{
- std::cout << "Destructor of A" << std::endl;
+ cout << "operator=" <<endl;
}
-};
-void f(A object)
-{ //Copy constructor of A
- std::cout << "f()" << std::endl;
-} //Destructor of A
+ ~Test()
+ {
+ cout << "Destructor" <<endl;
+ }
+};
-void g(A& object)
-{
- std::cout << "g()" << std::endl;
+void f(Test object)
+{
+ //do Stuff
}
+
+void g(Test& object)
+{
+ //do Stuff
+}
int main()
{
- A obj(3); //Constructor with one int parameter of A
- f(obj);
- g(obj);
+ Test t; //Default constructor;
+
+ Test t2(t) // Copy constructor
+ Test t3(t2) // Copy constructor
+ Test t2 = t3 // operator=
+ Test t3 = t // operator=
+
+ Test newTest = t; //Copy constructor !!!!!!!
+
+ f(t); // Copy constructor
+ g(t); // nothing. We are passing it as a reference. We are not copying it!
+
+ Test* ptr = new Test(); // Default constructor // we create a new object in the dynamic memory. The destructor must be invoked explicitly (with delete)
+
+ delete ptr; // Destructor
+
+} //Destructor Destructor Destructor Destructor
-} //Destructor of A
```