يحتوي الفيديو على شرح للقاط الاتية
00:00 - Intro
00:23 - Using new
02:49 - Using delete
05:20 - Problems with Free Store
09:30 - Resource Acquisition Is Initialization -
11:25 - Manager Object
15:46 - Overloading new
17:34 - nothrow new
19:57 - Outro
تحميل ملف العرض
16 Free Store.pdf (454.1% u)
الأمثلة
#include <iostream>
#include <vector>
void fun1() {
// Reserve memory for a single element initialized to 10
auto p1 = new int{10};
// Reserve memory for an array of size 10
auto p2 = new int[10];
int p3[10]{0};
delete p1;
delete[] p2;
// delete p3; // Error, p3 is not allocated by new.
}
void fun2() {
auto p1 = new int{10};
std::cout << "Value of p1 is " << *p1 << "\n";
This file has been truncated. show original
// Manager object example.
// TODO: implement the remaining constructors according to the rule of five.
#include <cstddef>
#include <iostream>
template <typename T, std::size_t N>
class Array {
public:
T* _data = new T[N];
~Array() { // non-default destructor
std::cout << "Destructor called" << std::endl;
delete[] _data;
};
void* operator new(std::size_t, void* p) { return p; };
};
This file has been truncated. show original