C ???? ??? ??? ????? ?? ? ? ???? ???? ?? ?? ?????. ?? ??? ?????. 1) ??? ??? ???? ??? ??? ?????. 2) ???? ??? ????? ??? ??? RAII? ?????. 3) ?? ???? ??? ?? ??? ??? ?? ??? ??????. 4) std :: shared_ptr? ?? ??? ???? ?? ??? ?? ??? ??? ?? ???? ???? ? ??????.
C? ??? ? ? ???? ???? ????? ???? ??? ???? ?? ?????. ?? ?? ??? ?? ?? ? ??? ??? ???. ???? C ???? ??? ???? ???? ? ??? ?? ??????
C ???? ???? ??? ??? ????? ?? ??? ?? ? ? ???? ???? ?? ?? ?????. ?? ???? ??? ??? ???? ??? ?? ?? ? ?? ??? ???? ????????. ???? ??? ??? ?? ????? ??????.
? ???? ??? ?? ? ?? ??????. ??? C? ?? ?? ??? ??????? - ????? ??? ?? ?? ???? ?? ?? ????.
?? ???, ?? ?? ???? ???? ???? ??? ??? ?? ??? ??????. ??? ?? ??? C '?? ??? ???? ?? ???????. ??? ??? ? ???? ?? ?? ?? ???? ??? ? ? ?? ???? ?? ??? ?????.
C?? ??? ?? ? ??? ?? ?? ???? ?? ? ? ????. ?? ??, ??? ???? ?????? ?? ??? ?? ? ? ?? ??? ??????. ??? ??? ? ?? ???? ??? ??????? ??? ???? ??? ????.
?? ? ??? ?? ??? ????.
#include <iostream> #include <???> ??? ?? ??? { ???: std :: ??? filename; ??* ??; ???: // ??? FileHandler (const std :: string & name) : filename (name), file (nullptr) { file = fopen (filename.c_str (), "r"); if (file == nullptr) { std :: cerr << "?? ?? ?? :"<< filename << std :: endl; } ? ?? { std :: cout << "??? ??? :"<< filename << std :: endl; } } // ??? ~ fileHandler () { if (file! = nullptr) { fclose (??); std :: cout << "?? ?? :"<< filename << std :: endl; } } }; int main () { ?? ??? fh ( "example.txt"); // ?? ?? ... ?? 0; }
? ???? main()
? ??? fh
??? ???? ??? ???? ?????? Destructor ~FileHandler()
? ???? ?????.
???? ???? ?? ?? ??? ???? ?? ????. ??? ?? ?? ??? ????? ?? ?? ????. ? ? ?? ?? ? ? ?? ???? ?? ??? ????.
- ?? ? ?? ?? : ???? ?? ????? ????? ?? ??? ???? ????. ??? ?? ??? ??? ??? ???? ??????? ?? ?????.
- Raii (?? ??? ???) : C 's Raii Idiom? ???? ?? ?????. ??? ??? ??? ????? ??? ?????? ???? ?????????.
- ?? ??? : ??? ?? ???? ?? ?? ?? ??? ???? ???? ??? ?? ??? ???? ???? ?????????.
??? ?? ??? ??? ????.
#include <iostream> ?????? { ???: ?? ~ base () { std :: cout << ""<< std :: endl; } }; ?? ?? : ?? ?? { ???: ~ davied () ??? { std :: cout << ""<< std :: endl; } }; int main () { Base* B = ??? ?? (); b ?? b; // ??? ?? ???? ????, ? ?????? ????? ?? 0; }
? ?? delete b
???? ??? ??? ?? ??? ?? ? ??? ???? ???? ??? ? ??????.
C? ?? ? ?? ???? ???? ???? ??? ????? ?????. ?? ??, ? ??? ??? ???? ?? ???? ??? ??????. ??? ??? ??? ??? ??? ???? ?? ??? ?? ? ????. ??? ??? ???? ??? ????.
#include <iostream> ??? A { ???: a () : b (nullptr) {} ~ A () { std :: cout << ""<< std :: endl; b ?? b; } void setb (??? B* newb) {b = newb; } ???: ??? B* B; }; ??? B { ???: b () : a (nullptr) {} ~ b () { std :: cout << "B ???"<< std :: endl; ?? a; } void seta (a* newa) {a = newa; } ???: a* a; }; int main () { a* a = new a (); b* b = ??? b (); a-> setb (b); b-> seta (a); ?? a; // ????? ?? ??? ????? ?? 0; }
? ???, a
???? b
? ?? ??? ???? ???? ?? ??? ?????. ??? ??? ??? ?? std::shared_ptr
?? std::unique_ptr
? ?? ??? ???? ??? ? ????.
std::shared_ptr
???? ?? ??? ?????? ??? ??? ????.
#include <iostream> #include <Memory> ??? A; ??? B; ??? A { ???: a () {} ~ A () { std :: cout << ""<< std :: endl; } void setb (std :: shared_ptr <b> newb) {b = newb; } ???: std :: shared_ptr <b> b; }; ??? B { ???: b () {} ~ b () { std :: cout << "B ???"<< std :: endl; } void seta (std :: shared_ptr <a> newa) {a = newa; } ???: std :: shared_ptr <a> a; }; int main () { auto a = std :: make_shared <a> (); Auto B = std :: make_shared <b> (); a-> setb (b); b-> seta (a); // a ?? b? ???? ??? ??? ????. ???? ????? ?? 0; }
std::shared_ptr
???? ? ?? ???? ?? ? ??? ???? ???? ?? ?? ??? ?? ? ????.
?????, ???? ?? ???? ???? ? C? ?? ?????. ??? ?? ??? ?? ?? ????. ??? ???? ?? ??? ??? ?????. ???? ????? ? ???? ????? ??? ??? ?????. ??? ??? ??? ???? ?? ? ????.
? ??? C ???? ?????? ???? ?? ??????? ?? ?????. ??? ??? PHP ??? ????? ?? ?? ??? ?????!

? AI ??

Undress AI Tool
??? ???? ??

Undresser.AI Undress
???? ?? ??? ??? ?? AI ?? ?

AI Clothes Remover
???? ?? ???? ??? AI ?????.

Clothoff.io
AI ? ???

Video Face Swap
??? ??? AI ?? ?? ??? ???? ?? ???? ??? ?? ????!

?? ??

??? ??

???++7.3.1
???? ?? ?? ?? ???

SublimeText3 ??? ??
??? ??, ???? ?? ????.

???? 13.0.1 ???
??? PHP ?? ?? ??

???? CS6
??? ? ?? ??

SublimeText3 Mac ??
? ??? ?? ?? ?????(SublimeText3)

??? ??











C? ???? ?? ??? ?? ???? ?? ???? ??? ??? ?? ???? ??????. 1) ?? ??? ?? ???? ?? ??? ??? ??? ??????. 2) ?? ??? ?????? ???? ?? ? ???? ?? ?? ??? ?????. ? ????? ????? ???? ?? ???? ??? ? ??? ?? ?? ? ?? ???? ??? ?????? ???????.

?, ?? ???? C? ??? ??, ?? ??? ? ??????. 1. ?? ???? ??? ??? ?? ?? ??? ?? ?? ??? ?????. 2. ????? ??? ?? ??? ?? ??? ??? ?? ? ??? ?????. 3. ??? ???? ?? ?? ???? ???? ?? ?? ??? ??? ????? ????? ???? ?????.

C? ???? ??? ???? ??? ?????? ? ?????. 1) ???? ???? ?? ??? ?? ??? ????? ?? ? ???? ?????. 2) ?? ?? ?? ??, ?? ?? ? ?? ???? ???????. 3) ???? ??? ??? ?? RAII ??? ???? ??? ???? ??????. 4) ?? ????? ?? ???? ???? ?? ? ??? ??? ???? ????????. 5) ?? ? ?? ??? ???? ?? ?? ???? ?? ? ? ????. 6) ??? ?? ???? ???? ???? ?? ???? ??????.

C? ? ?? ?? ??? ??? ??? : ??? ?? ??? ? ??? ???. 1. ??? ?? ???? ?? ??? ? ???? ?? ????? ?? ??? ????? ?? ???? ??? ? ????. 2. ??? ???? ?? ?? ? ??? ?? ???? ???? ??? ?? ?? ??? ?????.

1) ?? ? ?? ?? ??, 2) ?? ??? ???? ?? ???? ????, 3) ?? ???? ?? ??? ?? ??? ?? ???? 4) ?? ??? ??? ?? ??? ???? ??? ??? ??????. ???? ???? ?? ??? ??? ??? ?? ??? ??? ???? ?? ???? ?? ??? ???? ? ????.

?, C? ???? ?? ?????. 1) ??? ??? ?? ?? ? ??? ???? ?????. 2) ?? ???? ???? ??? ????. 3) ?? ??? ????? ??? ?? ???? ??? ??? ? ??????. ?? ? ??? ?? ???? ???? ??? ?????? ??? ?? ?????.

C DestructorsCanleadToSeVeralCommonerrors.toaVoidthem : 1) ?? ?? ?? ?? ?? ?? ???

C? ???? ??? ??? ? ??? ?? ????? ????. 1. ??? ???? ?? ??? ?? ????? ???? ??? ??? ???? ?? ? ? ????. 2. ??? ?? ???? ?? ??? ? ???? ?? ????, ??? ???? ?????.
