93.安卓iOS刷机原理通讲:分区映射、AVB校验、SHSH2验证机制深度拆解
2026/6/1 21:06:55
struct Point { int _x; int _y; }; int main() { int array1[] = { 1, 2, 3, 4, 5 }; int array2[5] = { 0 }; Point p = { 1, 2 }; return 0; }#include<iostream> #include<vector> using namespace std; struct Point { int _x; int _y; }; class Date { public: Date(int year = 1, int month = 1, int day = 1) :_year(year) , _month(month) , _day(day) { cout << "Date(int year, int month, int day)" << endl; } Date(const Date& d) :_year(d._year) , _month(d._month) , _day(d._day) { cout << "Date(const Date& d)" << endl; } private: int _year; int _month; int _day; }; // ⼀切皆可⽤列表初始化,且可以不加= int main() { // C++98⽀持的 int a1[] = { 1, 2, 3, 4, 5 }; int a2[5] = { 0 }; Point p = { 1, 2 }; // C++11⽀持的 // 内置类型⽀持 int x1 = { 2 }; // ⾃定义类型⽀持 // 这⾥本质是⽤{ 2025, 1, 1}构造⼀个Date临时对象 // 临时对象再去拷⻉构造d1,编译器优化后合⼆为⼀变成{ 2025, 1, 1}直接构造初始化 d1 // 运⾏⼀下,我们可以验证上⾯的理论,发现是没调⽤拷⻉构造的 Date d1 = { 2025, 1, 1}; // 这⾥d2引⽤的是{ 2024, 7, 25 }构造的临时对象 const Date& d2 = { 2024, 7, 25 }; // 需要注意的是C++98⽀持单参数时类型转换,也可以不⽤{} Date d3 = { 2025}; Date d4 = 2025; // 可以省略掉= Point p1 { 1, 2 }; int x2 { 2 }; Date d6 { 2024, 7, 25 }; const Date& d7 { 2024, 7, 25 }; // 不⽀持,只有{}初始化,才能省略= // Date d8 2025; vector<Date> v; v.push_back(d1); v.push_back(Date(2025, 1, 1)); // ⽐起有名对象和匿名对象传参,这⾥{}更有性价⽐ v.push_back({ 2025, 1, 1 }); return 0; }#include<iostream> #include<vector> #include<string> #include<map> using namespace std; int main() { std::initializer_list<int> mylist; mylist = { 10, 20, 30 }; cout << sizeof(mylist) << endl; // 这⾥begin和end返回的值initializer_list对象中存的两个指针 // 这两个指针的值跟i的地址跟接近,说明数组存在栈上 int i = 0; cout << mylist.begin() << endl; cout << mylist.end() << endl; cout << &i << endl; // {}列表中可以有任意多个值 // 这两个写法语义上还是有差别的,第⼀个v1是直接构造, // 第⼆个v2是构造临时对象+临时对象拷⻉v2+优化为直接构造 vector<int> v1({ 1,2,3,4,5 }); vector<int> v2 = { 1,2,3,4,5 }; const vector<int>& v3 = { 1,2,3,4,5 }; // 这⾥是pair对象的{}初始化和map的initializer_list构造结合到⼀起⽤了 map<string, string> dict = { {"sort", "排序"}, {"string", "字符串"}}; // initializer_list版本的赋值⽀持 v1 = { 10,20,30,40,50 }; return 0; }#include<iostream> using namespace std; int main() { // 左值:可以取地址 // 以下的p、b、c、*p、s、s[0]就是常⻅的左值 int* p = new int(0); int b = 1; const int c = b; *p = 10; string s("111111"); s[0] = 'x'; cout << &c << endl; cout << (void*)&s[0] << endl; // 右值:不能取地址 double x = 1.1, y = 2.2; // 以下⼏个10、x + y、fmin(x, y)、string("11111")都是常⻅的右值 10; x + y; fmin(x, y); string("11111"); //cout << &10 << endl; //cout << &(x+y) << endl; //cout << &(fmin(x, y)) << endl; //cout << &string("11111") << endl; return 0; }#include<iostream> using namespace std; int main() { // 左值:可以取地址 // 以下的p、b、c、*p、s、s[0]就是常⻅的左值 int* p = new int(0); int b = 1; const int c = b; *p = 10; string s("111111"); s[0] = 'x'; double x = 1.1, y = 2.2; // 左值引⽤给左值取别名 int& r1 = b; int*& r2 = p; int& r3 = *p; string& r4 = s; char& r5 = s[0]; // 右值引⽤给右值取别名 int&& rr1 = 10; double&& rr2 = x + y; double&& rr3 = fmin(x, y); string&& rr4 = string("11111"); // 左值引⽤不能直接引⽤右值,但是const左值引⽤可以引⽤右值 const int& rx1 = 10; const double& rx2 = x + y; const double& rx3 = fmin(x, y); const string& rx4 = string("11111"); // 右值引⽤不能直接引⽤左值,但是右值引⽤可以引⽤move(左值) int&& rrx1 = move(b); int*&& rrx2 = move(p); int&& rrx3 = move(*p); string&& rrx4 = move(s); string&& rrx5 = (string&&)s; // b、r1、rr1都是变量表达式,都是左值 cout << &b << endl; cout << &r1 << endl; cout << &rr1 << endl; // 这⾥要注意的是,rr1的属性是左值,所以不能再被右值引⽤绑定,除⾮move⼀下 int& r6 = r1; // int&& rrx6 = rr1; int&& rrx6 = move(rr1); return 0; }#define _CRT_SECURE_NO_WARNINGS 1 #include<iostream> #include<assert.h> #include<string.h> #include<algorithm> using namespace std; namespace test { class string { public: typedef char* iterator; typedef const char* const_iterator; iterator begin() { return _str; } iterator end() { return _str + _size; } const_iterator begin() const { return _str; } const_iterator end() const { return _str + _size; } string(const char* str = "") :_size(strlen(str)) , _capacity(_size) { cout << "string(char* str)-构造" << endl; _str = new char[_capacity + 1]; strcpy(_str, str); } void swap(string& s) { ::swap(_str, s._str); ::swap(_size, s._size); ::swap(_capacity, s._capacity); } string(const string& s) :_str(nullptr) { cout << "string(const string& s) -- 拷⻉构造" << endl; reserve(s._capacity); for (auto ch : s) { push_back(ch); } } // 移动构造 string(string&& s) { cout << "string(string&& s) -- 移动构造" << endl; swap(s); } string& operator=(const string& s) { cout << "string& operator=(const string& s) -- 拷⻉赋值" << endl; if (this != &s) { _str[0] = '\0'; _size = 0; reserve(s._capacity); for (auto ch : s) { push_back(ch); } } return *this; } // 移动赋值 string& operator=(string&& s) { cout << "string& operator=(string&& s) -- 移动赋值" << endl; swap(s); return *this; } ~string() { cout << "~string() -- 析构" << endl; delete[] _str; _str = nullptr; } char& operator[](size_t pos) { assert(pos < _size); return _str[pos]; } void reserve(size_t n) { if (n > _capacity) { char* tmp = new char[n + 1]; if (_str) { strcpy(tmp, _str); delete[] _str; } _str = tmp; _capacity = n; } } void push_back(char ch) { if (_size >= _capacity) { size_t newcapacity = _capacity == 0 ? 4 : _capacity * 2; reserve(newcapacity); } _str[_size] = ch; ++_size; _str[_size] = '\0'; } string& operator+=(char ch) { push_back(ch); return *this; } const char* c_str() const { return _str; } size_t size() const { return _size; } private: char* _str = nullptr; size_t _size = 0; size_t _capacity = 0; }; } int main() { bit::string s1("xxxxx"); // 拷⻉构造 bit::string s2 = s1; // 构造+移动构造,优化后直接构造 bit::string s3 = bit::string("yyyyy"); // 移动构造 bit::string s4 = move(s1); cout << "******************************" << endl; return 0; }