RAII
Në shqip përdoret i njëjti emër.
ShpjegimiSQ
RAII (Resource Acquisition Is Initialization) është ideja kryesore e C++: një burim (memorie, skedar, lidhje) e merr në konstruktor dhe e liron në destruktor. Kështu, kur objekti del nga scope-i, gjithçka pastrohet vetë — edhe nëse ndodh gabim.
EnglishEN
RAII (Resource Acquisition Is Initialization) is C++'s key idea: you grab a resource (memory, a file, a connection) in the constructor and release it in the destructor. So when the object goes out of scope, everything is cleaned up automatically — even if an error happens.
Si ta mendosh
Si dera e frigoriferit me drita: ndizet kur e hap, fiket vetë kur e mbyll — s'ke nevojë ta mbash mend.
Lexoje në anglisht
Like a fridge light: on when you open the door, off by itself when you close it — nothing to remember.
Shembull kodicpp
{
std::ifstream skedari("notat.txt"); // hapet
// ... lexo
} // mbyllet vetë këtu