C++ ??? ???: ???? ????
May 09, 2024 pm 09:27 PM??? ???? ? ??? ??? ???? ???? ??? ??? ??? ? ?? C++ ?? ??????. ??? ??? ????: Unique_ptr: ?? ???, ?? ??? ?????. shared_ptr: ?? ?????, ?? ???? ??? ??? ??? ? ????. Weak_ptr: ?? ??, ?? ??? ??? ?? ?? ??? ?????. ???: std ??????? make_unique, make_shared ? make_weak? ???? ??? ???? ????. ??? ???? ??? ??? ???? ?? ???? ?????. ?? ???: ??? ?? ???? ???? ??? ???? ??? ??? ? ????. ??? ???? ?? ??? ????? ???? ??? ??? ??? ? ????.
???? ????: C++ ??? ???
??
??? ???? ??? ?? ??? ????? ??? C++? ?? ??????. ???? ??? ???? ? ???? ??? ???? ?????? ??? ?? ? ??? ???? ?? ?? ??? ??? ?? ???? ???? ??? ??? ????? ?????.
??
C++?? ?? ?? ??? ??? ??? ??? ?? ??? ??? ??? ????.
- unique_ptr: ??? ????? ??? ? ?? ??? ???? ?? ??? ??? ??? .
- shared_ptr: ???? ???? ??? ????, ?? ???? ??? ??? ??? ??? ? ????.
- weak_ptr: ??? ?? ??? ??? ?? ?? ??? ??? ? ???? ?? ?? ??? ??????.
?? ???
??? ???? ???? std
???????? ?? ?? ???? ?????. std
命名空間中的相應(yīng)類型模板:
// 獨(dú)占所有權(quán) unique_ptr<int> p1 = make_unique<int>(42); // 共享所有權(quán) shared_ptr<int> p2 = make_shared<int>(10); // 弱引用 weak_ptr<int> p3 = p2;
釋放內(nèi)存
智能指針會(huì)在其作用域結(jié)束時(shí)自動(dòng)釋放所指向的對(duì)象。因此,不需要手動(dòng)調(diào)用 delete
或 free
。
實(shí)戰(zhàn)案例:動(dòng)態(tài)數(shù)組管理
使用智能指針管理動(dòng)態(tài)數(shù)組,可以避免因忘記手動(dòng)釋放空間而導(dǎo)致的內(nèi)存泄漏:
// 普通的動(dòng)態(tài)數(shù)組管理 int* arr = new int[100]; // 智能指針管理動(dòng)態(tài)數(shù)組 unique_ptr<int[]> arr = make_unique<int[]>(100);
當(dāng) arr
超出其作用域時(shí),智能指針會(huì)自動(dòng)刪除數(shù)組。這確保了在所有情況下都釋放了資源。
高級(jí)用法:自定義刪除器
某些情況下,可能需要使用自定義刪除器來控制指針指向?qū)ο蟮尼尫欧绞?。這可以通過重載 delete
class MyObject { public: ~MyObject() { // 自定義刪除邏輯 } }; int main() { unique_ptr<MyObject, decltype(&MyObject::delete)> p = make_unique<MyObject>(&MyObject::delete); }
Release memory
??? ???? ??? ??? ???? ?????. ??? ??? ????. ??? ????delete
?? free
? ??? ??? ????. ???? ??: ?? ?? ??????????? ???? ???? ?? ??? ???? ??? ???? ???? ?? ????? ???? ??? ??? ?????. ??rrreee??arr
? ?? ??? ???? ??? ???? ???? ??? ?????. ??? ?? ?? ??? ???? ?????. ???????? ???: ??? ?? ???????????? ?? ???? ???? ??? ???? ??? ???? ?? ??? ?? ???? ???? ? ?? ????. ?? delete
???? ?????? ??? ? ????. ??rrreee??????????????? ???? 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)

PHP? AI ??? ?? ??? ??? ?? AI ??? API (? : OpenAI, HuggingFace)? ?????? ???? ??? ???, API ??, ?? ?? ? ?? ?????? ???? ????. 2. ??? ??? ??? ??? AI ???? ???? ????. ?? ??? API, ??? ?? ? ??? ??? ???? ????. 3. ?? ??? ?? ??, ??, ??, ???, ??? ????? ? GPT ?? BART/T5? ?? ?? ??? ???????. 4. ?? ????? ??, ??? ?, ?? ?? ? ?? ?? ??? ?????. ?? ??? ???? ????? ???? ??? ???? ?? ?? ?? ? ??, ???? ?? ??, ?? ??, ?? ?? ? ??? ???????.

??? ?? ??? ? ???? ???? ? ???? C? ??? ???? ?? ?????. 1. ??? Intadd (Inta, Intb)? ?? ?? ? ??? ?? ?????. 2. ??? ?? ? ? ?? ??? ???? ??? ?? ? ? ?? ??? ??? ?????. 3. ?? ???? ??? ??? ??? ???? ?? voidGreet (StringName)? ?? ?? ???? void? ?????. 4. ??? ???? ?? ???? ?????, ??? ???, ?? ??? ???? ? ? ???, ?? C ?????? ?? ?????.

decltype? ??? ??? ?? ??? ???? ?? C 11?? ???? ??????. ?? ??? ???? ?? ??? ???? ????. 1. decltype (expression) ? ??? ???? ??? ???? ????. 2. ?? ?? decltype (x)? ?? ???? ???? ??, decltype ((x))? lvalue ???? ?? X? ?????. 3. ????? ?? ?? ?? ?? ?? AUTO-> DECTYPE (t u)? ?? ?? ?? ???? ? ?????. 4. ??? ?? ??? decltype (vec.begin ())? ?? ???? ???? ??? ? ? ????. it = vec.begin (); 5. ????? ?? ?? ???? ?????

C Follerexpressions? Variadic ?? ?? ????? ?? ??? ????? ?? C 17? ?? ?? ? ?????. 1. ?? ?? (Args ...) ?? (1,2,3,4,5)? ?? ???? ????? ??? ?????. 2. ????? (Args && ...) ?? ?? ??? ???? ???? ? ??? true? ?????. 3. ?? (std :: cout

C? ?? ?? ?? ??? ??? ????? ?? ???? ????? ??? ????. ?? ??? (?? : ??)??? ???, ?? intarr [] ?? std :: vectorvec? ?? ??? ? STL ????? ?????. ?? (? : conststd :: string & name)? ???? ?? ?? ??? ??? ?? ???? ??? ? ????. ??? ??? ????. 1. ???? ???? ??? ???? ????. 2. ??? ????? ???? ?? ??? ??? ?????. 3. ?? ???? ??? ???? ?? ?? ??? ?????. ??? ?? ???? ?????? ??? ????? ???? ??? ? ????.

AbinarySearchTree (BST) IsabinaryTreewheretHeleftSubtreeContainlynodeswithValuessThanthenode 'svalue, grightSubtreecontainsonlynodeswithValuestthanThantenode'svalue ? bothsubtreesmustalsbsts;

? ??? jQuery? ???? ? ????? ?? ?? ??? ??? "All/No All Select"??? ???? ??? ???? ?????. ? ?? ?? ?? ??? ?? HTML ?? ? ??? ??? ???? ?? JQuery ??? ?? ??? ???? ? ???? ??? ???? ??? ????? ?? ? ? ????. ? ???? "?? ??"??? ??? ??? ??? ?? ???? ???? ?? ???? ??? ?? ? ? "All Select"??? ?????? ?? ??? ??? ??? ??? ?? ??? ?????.

C?? Python ????? ????? Pythoncapi? ?? ??? ?????. ?? ???? ??? ? ?? ??? ???? ??? ?? ? ?? ????? ???? ??????. ?? ??? ??? ????. 1. Py_Initialize ()? Python ???? ??????. 2. pyimport_import ()? Python ???? ?????????. 3. pyobject_getattrstring ()? ?? ?? ??? ????. 4. pyobject_callobject ()? ???? ?? ??? ???? ??? ??????. 5. Py_decref () ? py_finalize ()? ???? ???? ???? ???? ?????. ? ???? Hello? ????? ?????
