Iconic Trio Rule of Three
Name a more iconic trio... I'll wait class rule_of_three { char *string; // raw pointer used as a handle to a dynamically-allocated memory block void init(const char* s) { std::size_t n = std::strlen(s) + 1; cstring = new char[n]; std::memcpy(cstring, s, n); // populate } public: rule_of_three(const char* s = "") { init(s); } ~rule_of_three() { delete[] cstring; // deallocate } rule_of_three(const rule_of_three& other) // copy constructor { init(other.cstring); } rule_of_three operator=(const rule_of_three& other) // copy assignment { if (this != &other) { delete[] cstring; // deallocate init(other.cstring); } return *this; } };
На изображении Ким Кардашьян, Кайли Дженнер и Хлои Кардашьян стоят вместе под подписью «Name a more iconic trio... I'll wait». Ниже показан код C++ с правилом трёх: шутка сравнивает знаменитое трио сестёр с тремя специальными функциями управления памятью — конструктором копирования, оператором присваивания и деструктором. EN: Kim Kardashian, Kylie Jenner, and Khloé Kardashian stand together beneath the caption “Name a more iconic trio... I'll wait.” Below them is C++ code demonstrating the rule of three: the joke compares the iconic trio of sisters with the three special memory-management functions—a copy constructor, copy-assignment operator, and destructor.
three women / три женщиныblonde woman / блондинкаwoman with dark hair / женщина с тёмными волосамиwhite crop top / белый топblack sleeveless top / чёрный топ без рукавовsilver dress / серебристое платьеbeige skirt / бежевая юбкаlong blonde hair / длинные светлые волосыnecklace / ожерельеhandbag strap / ремешок сумкиwood-paneled wall / деревянная панельная стенаC++ code / код C++text caption / текстовая подпись
- @profunctor_io / 5641 2020-10-21
- Type
- image
- Size
- 471×800 · 84.0 KiB
- Mood
- ироничный, умный
- Language
- en
- Added