C++ const members and static members

const members and static members Cont members of class const data members Const data members can only be initialized through a constructor initializer list. class Box {<!– –> private: const int length; //Length const int width; //width const int height; //height public: Box(); Box(int H, int W, int L); }; Box::Box(int H, int W, int […]

C++: Encapsulation principle of map and set

Article directory Red-black tree packaging Encapsulation of map and set Implementation of red-black tree iterator Implementation of operator + + and — ++ implementation process Other modules for iterators For implementing const solution to set map solution overall implementation This article was written after the red-black tree simulation was implemented, and map and set were […]

[C++] Non-type template parameters | array container | template specialization | why templates cannot be compiled separately

Table of Contents 1. Non-type template parameters 2. array container 3. Template specialization Why specialize templates? Function template specialization Add a question Class template specialization Full specialization and partial specialization Fully specialized partial specialization 4. Why templates cannot be compiled separately Why what to do 5. Summarize the advantages and disadvantages of templates 1. Non-type […]

C++ double to string

#include “iomanip” #include <iostream> using namespace std; bool to_int(double value,int & amp; res){ res=int(value); //If the result is min_int/max_int, there is a high probability that the value exceeds the limit, unless the value is exactly equal to 2147483647/-2147483648 return (res > -2147483648 & amp; & amp; res < 2147483647); } string double_to_string(double value,int decimal,bool append_zero) […]

How C/C++ runs and its distribution in memory

C/C++ Restart? 1.0 Question: How does the written C++ code run? In the following order from left to right Writing source code Preprocessing Compilation Assembly Linking Loading Execute() Writing source code: writing in high-level programming languages, such as following C/C++ syntax rules to write good code correctly Preprocessing: Before compilation, the preprocessor processes header files […]

C++ optimizes the use of strings

String properties Strings are dynamically allocated Strings are values Strings are copied a lot String optimization Basic optimization Compound assignment operations avoid temporary strings Allocate memory in advance Use constant references to reduce temporary objects generated when passing parameters Eliminate copying of the returned string C-style optimization: use character arrays instead of strings Algorithm optimization: […]

c/c++ pointers #2

Table of Contents Table of Contents 1: Arrays and pointers 1.1: Understanding array names 1.2: Using pointers to access arrays 1.3: The essence of array parameter passing 2: Secondary pointer 3: Pointer array 4: Array pointer 5: Character pointer 6: Function pointer 7: Array of function pointers 1: Array and pointer Definition: Pointer variables are […]

<1>, C++ implements multi-thread synchronization processing: controlling the output sequence of ABC, outputting 10 groups, mutex+condition_variable

Table of Contents need: analyze: Some code implementation: 1. Operations implemented using only flag bits: 2. For greater security, the mutex lock code is added: 3. Use it with unique_lock to make the code safer Four: Use guard lock lock_guard to work with it 5. You can also use condition variables to process, which will […]

[C++] stack, queue and deque

Introduction to stack Stack is a container adapter that is specially used in contexts with last-in-first-out operations. Its deletion can only insert and extract elements from one end of the container. Stack is implemented as a container adapter. A container adapter encapsulates a specific class as its underlying container and provides a set of specific […]