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 14: Types of Heritage and Protected Access
🔹 1. Types of heritage in c ++Type details
Single one base → a derivative class
Multi -level base → derived1 → derived2
Many are inherited from a derived class 2+ base
A base class ingested → Many derivative classes
Two or more hybrid combination
📌 Single Heritage (Review)
CPP
Copy
edit
Class animal {
public:
Eat zero () {
Cout << "Food ..." << Endl;
,
,
Class Dog: Public Animal {
public:
Zero bark () {
Cout << "Barking ..." << Endl;
,
,
📌 multilevel heritage
CPP
Copy
edit
Class living
public:
Zero Breath () {Cout << "Breath" << Endl; ,
,
Class Animal: Public Living
public:
Eat zero () {cout << "eating" << endl; ,
,
Class Dog: Public Animal {
public:
Zero bark () {cout << "barking" << endl; ,
,
📌 Many heritage
CPP
Copy
edit
Class printer {
public:
Zero print () {cout << "printing" << Endl; ,
,
Class scanner {
public:
Zero scan () {cout << "scanning" << Endl; ,
,
Class machine: public printer, public scanner {
// Heritage prints () and scan ()
,
📌 hierarchical heritage
CPP
Copy
edit
Class vehicle {
public:
Void start () {cout << "starting engine" << endl; ,
,
Class car: public vehicle {};
Class bike: public vehicle {};
📌 hybrid heritage
Attention Can cause ambiguity, solved using virtual heritage (later cover).
🔹 2. Protected access referring
Like private, but accessible in derived classes.
CPP
Copy
edit
Class base {
reserve:
Int x = 10;
,
Class derivative: Public base {
public:
Zero show () {cout << "x =" << x << endl; ,
,
🧠 day 14 practice
Apply a multi -level heritage: Person → Employees → Manager.
Create a class A, B, and a class C who inherited
Comments
Post a Comment