OOP & C++ Flashcards
Flashcards for OOP and C++ covering classes, inheritance, polymorphism, and STL for C-CAT preparation. Essential revision material for C-CAT aspirants.
What are the four pillars of OOP?
Encapsulation, Abstraction, Inheritance, Polymorphism
Default access specifier in a C++ class
private (a struct defaults to public instead)
What does a pure virtual function look like, and what does it do?
virtual void f() = 0; — makes the class abstract, uninstantiable
Why must a base class destructor be virtual?
So deleting a derived object via a base pointer also runs the derived destructor — otherwise cleanup is skipped
Constructor execution order in inheritance
Base class constructor runs first, then the derived class constructor
Destructor execution order in inheritance
Reverse of construction — derived class destructor first, then base
What does the 'this' pointer refer to?
A pointer to the calling object, implicitly passed to every non-static member function
How many copies of a static data member exist across all objects of a class?
Just 1 — shared by the entire class, not per-object
What problem does virtual inheritance solve?
The diamond problem — duplicate copies of a shared base class
Difference between function overloading and overriding
Overloading = same name, different parameters, resolved at compile-time. Overriding = same signature in a derived class, resolved at runtime, needs virtual
Which operators cannot be overloaded in C++?
:: (scope resolution), . (member access), .*, ?: (ternary), sizeof, typeid
What must new[] be paired with?
delete[] — mismatching it with a plain delete causes undefined behavior
What is a friend function?
A non-member function explicitly granted access to a class's private and protected members
Which STL container keeps its elements in sorted order automatically?
std::map — implemented as a self-balancing tree (typically Red-Black)
Deck Complete!
You've reviewed all 14 cards.
📖 Study first: View Cheat Sheet