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 13: Heritage Basics
🔹 1. What is inheritance? The inheritance allows a square (derivative/child) to obtain qualities and methods from another class (base/parent). This helps reusion the code and establish relationships like "IS-A". 🔹 2. Syntax CPP Copy edit Class base { public: Zero Show () { cout << "base class method" << Endl; , , Class derivative: Public base { public: Zero display () { cout << "derived class method" << endl; , , int main() { Derved OBJ; Obj.show (); // Aadhaar Obj.display (); // derived from Return 0; , 🔹 3. Inheritance Access Specifier Aadhaar Member Public Heritage Protected Heritage Private Heritage Publicly protected private Protected protected private Private heritage has not been inherited by not inherited Example: CPP Copy edit A class { public: Int x; reserve: Int y; Personal: Int z; , Class B: Public A { public: Zero Show () { cout << x; // Ok cout << y; // Ok // Cout << Z; // Mistake , , 🔹 4. Inheritance constctor and distribution order The base class construction is called before the derivative class. The destructive is called in the reverse order. CPP Copy edit A class { public: A () {cout << "base constitution \ n"; , ~ A () {cout << "base disastrous \ n"; , , Class B: Public A { public: B () {cout << "derivative constructor \ n"; , ~ B () {cout << "derivative disastrous \ n"; , , 🔹 5. Single versus multi -layered heritage ✔ single heritage CPP Copy edit A class {}; Class B: Public A {}; ✔ multi -level heritage CPP Copy edit A class {}; Class B: Public A {}; Class C: Public B {}; // C inherited A and B 🔹 6. Function overrising The derivative class can override the methods of the base class with the same signature. CPP Copy
Comments
Post a Comment