From bfc9b6ecd3f36a9c137d63fe93ff2f0f2d931442 Mon Sep 17 00:00:00 2001 From: Alessandro Ferro <49845537+xfarrow@users.noreply.github.com> Date: Fri, 26 Mar 2021 11:01:56 +0100 Subject: [PATCH] Lezione 5 --- teoria/classi/a.out | Bin 0 -> 13360 bytes teoria/classi/constructorStack.cpp | 51 +++++++++++ teoria/classi/destructor_problem.cpp | 66 ++++++++++++++ teoria/classi/methods.cpp | 38 +++++++- teoria/classi/multiple_inheritance.cpp | 77 +++++++++++++++++ .../classi/multiple_virtual_inheritance.cpp | 81 ++++++++++++++++++ teoria/classi/single_inheritance.cpp | 43 ++++++++++ .../esempi_professore/examples/classes/a.out | Bin 0 -> 14016 bytes 8 files changed, 355 insertions(+), 1 deletion(-) create mode 100755 teoria/classi/a.out create mode 100644 teoria/classi/constructorStack.cpp create mode 100644 teoria/classi/destructor_problem.cpp create mode 100644 teoria/classi/multiple_inheritance.cpp create mode 100644 teoria/classi/multiple_virtual_inheritance.cpp create mode 100644 teoria/classi/single_inheritance.cpp create mode 100755 teoria/esempi_professore/examples/classes/a.out diff --git a/teoria/classi/a.out b/teoria/classi/a.out new file mode 100755 index 0000000000000000000000000000000000000000..bda8eae850163a487efe6ce20853cec4cfbac147 GIT binary patch literal 13360 zcmeHOZ*WxA6~CKJAYxb+3>f(%4=W=PSrP~siqve9g|`|oCIM{=J~z7?vURhY*?p@4 zi&8;`9U7alj>CsKb*vxSnRW(RKVWq#8i!(M+Tx!|rF4ec>I6r}bW|p_!1j0UyJz?9 z%dVqNKjzNto_l}i&pr3t`|jr6ck*zcV`GKOCAhf7w*{ z^_m*loJ8XmESR$1ozNpczija;!7kNbxwwod|C#bUtc=Hc*EX$;M^?mRiOkT7q2{$K z);9UlN#80tZn96Zo3?C~JyBRWROE9lK7F@PWysiZ6Az*V#;6BKg!e1{VKTrl=RL0KpW#ktF*YI(c z+sfFXxN1&ewAYuxDf*?xbp`Ct7Ii|?G)N%2Xv>0mO`DPM^5ry_YlUI#97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rB+mTqp$fToWh!To8hp44RrVJrXh?0Z8esYwuqf(DB!|9~akFZeE zmh?m=V>PxRWvc7;ZW?_dv1zgwUn8H&;R1SX!}zVf&}g-S;m8MbDAD}dvabq$HNjt` zqVdd85*cM~In-sJa-;@Lf|Z#i1JG(^iW$A>bOCi{tdWevqLtwlPG{tL_~PWaf-F5I zvRjG(R)8~4tS~M)>m?HKzDkl^vCG1j-Zfx`dO^*UMf`0S$)vu1wxf(w)_#4YAe7<4I=W4~4vRo(n4SeV*!1{a+Vyb~>FZ}ljV~wcT_4&NS z^m-Ol)T!SN`~uFh+&`bIn6f^f{~doei!IQnpEA}zt}0ABDL5!}Y@#ab^SOK*F#I&- z_4%B}lqxubXMp7`8>yz^H+l9r}E}W*TQfMV;|~$)V5ZaHc2K`e8H9 z{$B%wj%pkxK0k5(zB68|&-5?Qon_PKbN${$08v=ZY8Bdy{{swKd)z;t|M~wT_`%@y z$$IP;oquVFd3|*scyKX56kh*UYjXb|fMM6q|NXC78r+XlpWEZ8kWbt{=lyy$OQOyZ ze+64ie1C=yi8SO9tHS#A4xG)|DX%@dXp3gG_&KECnU(l({CNMM_07Ip8rJvt4HnHg ZnA|VR&PK%{B3U0Vw +using namespace std; +class A{ +public: + int x; + A(){ + cout<<"Sono nel costruttore di A"< +using namespace std; + +void problema(); +void soluzione(); + +int main(){ + //problema(); + soluzione(); + return 0; +} + +void problema(){ + class A{ + public: + int* v = new int[10]; + ~A(){ + cout<<"Richiamato distuttore di A"< +class ClassName{ +private: + int y = 5; +public: + int x = 3; + + int aggiungiX(int); // dichiarazione funzione + + int aggiungiY(int); // dichiarazione funzione + friend int aggiungiY(int); // dichiarazione friendship +}; +/* + NB: in questo caso x deve essere dichiarata pubblica. Se fosse stato un metodo + all'interno della classe allora avrebbe potuto avere accesso anche se x + fosse stata privata +*/ +int ClassName::aggiungiX(int parametro){ + x+=parametro; +} +/* + Oppure si può dichiarare la friendship per accedere a variabili private/protette +*/ +int ClassName::aggiungiY(int parametro){ + y+=parametro; + std::cout< +using namespace std; + +/* + ereditarietà a diamante: + A <-- B + A <-- C + B <-- D + C <-- D +*/ + +class A{ + public: + int a; + A(){ + cout<<"A created"< +using namespace std; +/* + ereditarietà a diamante: + A <-- B + A <-- C + B <-- D + C <-- D +*/ + +void nonVirtualInheritance(); +void virtualInheritance(); +int main(){ + //nonVirtualInheritance(); + virtualInheritance(); + return 0; +} + +void nonVirtualInheritance(){ + class A{ + public: + int size = 7; + }; + + class B : public A{ + public: + int b; + }; + + class C : public A{ + public: + int c; + }; + + class D : public B, public C{ + public: + int d; + }; + + /* + Adesso B ha una copia di A, C ha una copia di A, D ha una copia di B e una + copia di C. Implica che D ha due copie di A. + Se provo a stampare size, cosa succede? + */ + D obj; + //cout< +using namespace std; +class A{ +private: + int a = 1; +protected: + int b = 2; +public: + int c = 3; + int sameVariable = 4; +}; + +class B : A{ +public: + int sameVariable = 9; + void test(){ + //cout<^XWYOd=!6Y}JS@zMX_g{Q- z?76S}lz3T(H7>u@$9}J#u51BI$#N9NHx}vrCa{%7@VmiZ41cEt|6mFH_7ZwFm%#tI zgq|;#z}ExU@aHZ~CG?*tfm0kcw-U5(EP>N37K_g{(7!^g5t^of19OJ9ELb0DGaA{t zmDa>AVHk%8lS4+@45v)P5Jr2?J|h}S#SX{QW-QgSuO*QjiuHv15;3c|q|sI#rBJK1f7$lAz=F&s;!lSAP|+#EHI)Pk$qtd9*v z6YY_1v#u^O5Kb9pDjYY{?U7KZ3)l{*jYo`R+Dyg5gY7*=PpuK^-UW9T8g8)+cbkcH z`zKQu>4CDHM(52D%auqnW7@9YEfBE7k%*C|c-0A`cj#z*C~9=Y(wV^+bw)Ulh+*U& zBQkK0(I1W{FxJRO*a(}kkvP=JMt__}eGH*ANKi$6FdQEeds|wJ9f4ZWa`0fVx!tG> z>=1i9+MCe?TyNEl?T*^^z)qUaGF+|n=f%}azqAK0R#!B&J@~gBbI6uO8vF?d+o38fr@hRn36HKd;?pjSNy=ie?awtU95`7t7u34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