C++ Classes and Inheritance: Object-Oriented Programming Guide Episode 12 (Updated June 2026) (Updated June 2026)
C++ is not a beginner language — and that is exactly why it commands premium salaries. While Python dominates the AI-scripting layer and NASSCOM-Deloitte projects 1.25 million AI-skilled professionals needed by 2027, C++ dominates where raw performance is non-negotiable: automotive ECU firmware at Bosch Pune, real-time control systems at KPIT Technologies, game engine development, and high-frequency trading systems. TCS reported 12,000 role eliminations in July 2025 — but their C++ and embedded systems openings increased simultaneously, because those roles cannot be automated by the tools doing the automating. Episode 12 of our C++ Essentials series covers the core of Object-Oriented Programming: classes, constructors, destructors, access specifiers, inheritance, and virtual functions. This is where C++ stops being "C with extra steps" and becomes a full OOP language.
- A C++ class is a user-defined type that bundles data (member variables) and behaviour (member functions) together
- Constructors initialize an object's state when it is created; destructors clean up when the object is destroyed
- Access specifiers — public, private, protected — control which code can access which members
- Inheritance lets a derived class reuse and extend the implementation of a base class
- Virtual functions enable polymorphism — the derived class version is called even through a base class pointer
What Is a Class in C++? Syntax, Members and Objects
A C++ class is a blueprint for creating objects. It defines the data (member variables) and behaviour (member functions, also called methods) that every object of that class will have. The syntax is: class ClassName access_specifier with member_variables and member_functions. For example, a Vehicle class might have member variables make (string), model (string), and engine_cc (int), and member functions like start(), stop(), and getSpeed(). When you create an object — Vehicle car1; — the object gets its own copy of all member variables. Member functions operate on the specific object they are called on. C++ classes differ from C structs primarily in two ways: classes default to private access (all members inaccessible from outside the class unless explicitly made public), while structs default to public. In practice, classes are used for complex objects with private data and public interfaces; structs are used for simple data containers. The this pointer is an implicit pointer available inside every non-static member function that points to the current object. It is used to disambiguate between member variables and local variables of the same name, and to return the current object from a method. At KPIT Technologies (Bavdhan, Pune 411021) and Bosch Pune (Adugodi), C++ classes are used extensively in automotive middleware — the AUTOSAR adaptive platform is largely built in modern C++ with classes and templates.

Constructors, Destructors and Access Specifiers
A constructor is a special member function called automatically when an object is created. It has the same name as the class, no return type, and is used to initialize member variables to valid starting states. The default constructor takes no arguments. A parameterized constructor takes arguments to initialize members with specific values at creation time. A copy constructor takes a const reference to another object of the same class and initializes the new object as a copy. If you do not define any constructor, the compiler provides a trivial default constructor that leaves variables uninitialized — a common source of undefined behaviour bugs in C++. Constructor initializer lists (using : before the opening brace) are more efficient than assigning values inside the constructor body, because they initialize rather than default-initialize and then assign. A destructor is called automatically when an object goes out of scope or is deleted. It is used to release dynamically allocated memory, close file handles, and release other resources. If your class allocates memory with new in its constructor, the destructor must call delete — failing to do so is a memory leak. This is why modern C++ prefers smart pointers (unique_ptr, shared_ptr) over raw pointers for resource management. Access specifiers control member visibility: public members are accessible from anywhere. private members are accessible only from within the class's own member functions and friends — this is the standard for member variables to enforce encapsulation. protected members are accessible from the class and its derived classes, used specifically for inheritance hierarchies. At Tata Technologies (Hinjewadi, Pune 411057) and Infosys Pune, C++ OOP knowledge is tested in technical interviews — especially the "what is encapsulation and why use private members?" question.
| OOP Concept | C++ Feature | Keyword | Purpose |
|---|---|---|---|
| Encapsulation | Private member variables with public getters/setters | private, public | Hide internal data, expose controlled interface |
| Inheritance | Derived class extends base class | class D : public B | Reuse and extend base class behaviour |
| Polymorphism | Virtual function override | virtual, override | Call derived version through base pointer |
| Abstraction | Abstract base class | virtual f() = 0 | Define interface, prevent direct instantiation |
| RAII | Constructor acquires, destructor releases | Constructor / Destructor | Automatic resource management, no memory leaks |
Inheritance: Base and Derived Classes in C++
Inheritance allows a derived class to inherit member variables and functions from a base class, extending or specializing them. The syntax uses a colon and access specifier: class Derived : public Base. Public inheritance (the most common) preserves access levels from the base class — public members of Base are public in Derived, protected members of Base are protected in Derived. Protected inheritance makes all public and protected members of Base protected in Derived. Private inheritance makes all public and protected members of Base private in Derived. With public inheritance, the derived class IS-A base class — a Car IS-A Vehicle, so a Car object can be used anywhere a Vehicle is expected. This is the Liskov Substitution Principle: derived class objects must be substitutable for base class objects without breaking the program. The derived class can override base class functions by defining a function with the same name and signature. Without the virtual keyword in the base class, this is function hiding (base class version called when accessing through a base pointer). With virtual, it is proper polymorphic override. The derived class constructor must explicitly call the base class constructor if the base class does not have a default constructor, done via the member initializer list. Multiple inheritance — a class inheriting from more than one base class — is possible in C++ but introduces the Diamond Problem when two base classes share a common ancestor. Virtual inheritance resolves this.

Polymorphism, Virtual Functions and C++ Career Scope in India
Virtual functions are the mechanism that enables runtime polymorphism in C++. When a base class declares a function virtual, and a derived class overrides it, calling the function through a base class pointer or reference invokes the derived class version — even though the pointer type is Base. This is called dynamic dispatch, resolved at runtime via the vtable. Without virtual, the base class version is always called regardless of the actual object type (static dispatch, resolved at compile time). The override keyword (C++11) on the derived class function asks the compiler to verify that it actually overrides a virtual function — if you misspell the name or get the signature wrong, the compiler catches it. Pure virtual functions (declared as = 0 in the base class) have no implementation in the base class and make the class abstract — you cannot instantiate an abstract class, only derive from it. Industry use: KPIT's vehicle diagnostics stack uses polymorphic UDS service handlers where each derived service class overrides a virtual execute() method. Bosch Pune's sensor fusion middleware uses abstract base classes for different sensor types — camera, radar, LiDAR — all accessed through a common ISensor interface. Named C++ recruiters in Pune: KPIT Technologies (35 Rajiv Gandhi IT Park, Bavdhan, Pune 411021), Bosch Pune (Adugodi Plant, Pune), Tata Technologies (Hinjewadi Phase 1, Pune 411057), Persistent Systems (Bhau Patil Road, Bopodi, Pune 411020), and Qualcomm India (Hinjewadi Phase 1, Pune). According to AmbitionBox 2025–26, C++ software engineers in Pune earn ₹5.0–8.5 LPA at 1–3 years experience and ₹10–18 LPA at mid-level embedded and automotive roles.
Maharashtra's CMYKPY (Chief Minister Yuva Karya Prashikshan Yojana) pays ₹6,000–10,000 per month while you complete approved industrial training. ABC Trainings' AI Powered Application Development workshop in Pune covers C++ fundamentals through advanced OOP and embedded systems patterns, aligned with PMKVY 4.0 standards. Apply for CMYKPY alongside your enrollment — students from our Pune Wagholi, Hadapsar, and Osmanpura batches have used this stipend to fund their training in 2025–26.Get the IT Brochure + Fees + Batch Dates on WhatsApp
Free 1:1 counselling. Placement track record. CMYKPY/PMKVY eligibility check.
💬 Get Brochure on WhatsApp📞 Call 7039169629About the author: Rahul Patil. 12 yrs experience training engineers across Maharashtra.
Visit Our Centers
- Wagholi (Pune): 1st Floor, Laxmi Datta Arcade, Pune-Ahilyanagar Highway. Call 7039169629
- Hadapsar (Pune HQ): 1st Floor, Shree Tower, opp. Vaibhav Theater, Magarpatta. Call 7039169629
- Cidco (Chh. Sambhajinagar): Kalpana Plaza, opp. Eiffel Tower, N-1 Cidco. Call 7039169629
- Osmanpura (Chh. Sambhajinagar): S.S.C Board to Peer Bazar Road, near Jama Masjid. Call 7039169629
- Sangli: Shubham Emphoria, 1st Floor, Above US Polo Assn., Sangli-Miraj Rd, Vishrambag. Weekend batches available. Call 7039169629
FAQs
What is the difference between a class and a struct in C++?
The only technical difference between a class and a struct in C++ is the default access specifier: class members default to private, struct members default to public. By convention, classes are used for complex objects with private data, encapsulated behavior, and public interfaces. Structs are used for simple data containers — plain old data (POD) types — where all members are public and there is minimal logic. Both support constructors, destructors, inheritance, and virtual functions.
When must I write a destructor in a C++ class?
You must write a destructor whenever your class directly manages a resource that needs to be released — dynamically allocated memory (new), open file handles, database connections, mutexes, or network sockets. If your class allocates memory with new in its constructor and the destructor does not call delete, every object creation causes a memory leak. In modern C++17 and later, prefer smart pointers (unique_ptr, shared_ptr) which manage deallocation automatically, often eliminating the need for a custom destructor.
What is the difference between function overriding and function overloading in C++?
Function overriding occurs in inheritance — a derived class redefines a virtual function from the base class with the same name and signature. The derived version replaces the base version for objects of the derived type (runtime polymorphism). Function overloading occurs within the same class or scope — multiple functions with the same name but different parameter lists (different types or counts). The compiler selects the correct overload at compile time based on the argument types. These are completely independent mechanisms with different purposes.
Which industries in Pune hire C++ developers and what salary can I expect?
C++ is in high demand in embedded systems, automotive software, and high-performance computing. Key Pune recruiters include KPIT Technologies (Bavdhan — automotive middleware and diagnostics), Bosch Pune (Adugodi — ADAS, sensor fusion, embedded ECU), Tata Technologies (Hinjewadi — product engineering services), Persistent Systems (Bopodi — product development), and Qualcomm India (Hinjewadi — chipset firmware). According to AmbitionBox 2025–26, C++ engineers earn ₹5–8.5 LPA at 1–3 years in Pune, rising to ₹12–22 LPA in senior embedded and ADAS roles at automotive tier-1 companies.
