C++ Day 39 STL Containers (Deep Understanding & Real Usage) Till now, you already know arrays, vectors, loops, and STL algorithms. Today, we go one step deeper and understand STL containers , which are the backbone of modern C++ programming. In real projects and competitive coding, choice of container matters a lot. 1. What are STL Containers? STL containers are data structures provided by C++ to store data efficiently. They handle: memory management resizing element access performance optimization You focus on logic , not memory handling. 2. Categories of STL Containers STL containers are mainly divided into: Sequence Containers Associative Containers Unordered Containers Container Adapters 3. Sequence Containers These store data in sequence . 3.1 Vector Most used container in C++. vector< int > v; Key Features: Dynamic size Contiguous memory Fast random access Slower insertion in middle Example: v. push_...
C ++ Day 11: Constructors, Districts, and this pointer
🔹 1. Types of constructors 📌 a. Default constctor If no argument is passed, it is said automatically. CPP Copy edit Class car { public: car() { Cout << "Default Constory" << Endl is called Endl; , , 📌 b. Parlokik manufacturer The object takes the argument to the members to initiate. CPP Copy edit Class car { public: String brand; Car (String B) { Brand = B; , , 📌 c. Copy manufacturer Creates a new object as a copy of an existing object. CPP Copy edit Class car { public: String brand; Car (string b) {brand = B; , // Copy constctor Car (Constate Car & C) { Brand = C.Brand; , , 🔹 2. Disastrous A destroyer is used to clean up an object. When the object is out of scope, it is called automatically. CPP Copy edit Class car { public: car() { Cout << "The constitution is called" << Endl; , ~ Car () { Cout << "The destroyer is called" << Endl; , , 🔹 3. This indicator (depth) This indicator refers to the current object example. Useful for decomposing the member variable and returning the object. CPP Copy edit Class person { public: String name; Person (string name) { This-> name = name; , Zero Show () { cout << "name:" << it-> name << endl; , , 🔹 4. Constitution overloading You can have several construents with different parameters lists in the same category. CPP Copy edit Class point { public: Int x, y; point() { X = 0; Y = 0; , Point (Int A, Int B) { x = a; y = b; , , 🔹 5. Deep Copy vs Shallow Copy (Intro) When your class handles the dynamic memory (pointers), copy constructs and distraiters help avoid memory issues. It will be detected
Comments
Post a Comment