Master Cpp Programming with 50 free flashcards. Study using spaced repetition and focus mode for effective learning in Programming.
The four pillars of OOP are:
Encapsulation – bundling data and methods togetherAbstraction – hiding complex implementation detailsInheritance – deriving new classes from existing onesPolymorphism – using a single interface for different types
A class is a user-defined type that encapsulates data members and member functions. Defined with the class keyword:class MyClass { public: int x; void show(); };
The only default difference is access control:class members are private by defaultstruct members are public by defaultBoth can have methods, constructors, and inheritance.
Inheritance allows a derived class to inherit members from a base class:class Dog : public Animal { };
This promotes code reuse and establishes an is-a relationship.
A virtual function is declared with the virtual keyword in a base class, enabling runtime polymorphism:virtual void speak() { }
Derived classes can override it, and the correct version is called via a base class pointer using the vtable.
A pure virtual function has no implementation in the base class and is declared as:virtual void draw() = 0;
Any class containing a pure virtual function becomes an abstract class and cannot be instantiated directly.
A virtual destructor ensures that when deleting an object through a base class pointer, the derived class destructor is called first:virtual ~Base() { }
Without it, derived resources may leak.
Operator overloading lets you redefine how operators work for user-defined types:MyClass operator+(const MyClass& rhs) const { return MyClass(value + rhs.value); }
Most operators can be overloaded except ::, ., .*, and ?:.
The << operator is typically overloaded as a friend function:friend std::ostream& operator<<(std::ostream& os, const MyClass& obj) { os << obj.data; return os; }
Namespaces group identifiers to avoid name collisions:namespace Math { int add(int a, int b); }
Access with Math::add(1,2) or bring into scope with using namespace Math;.
The std namespace contains the entire C++ Standard Library, including containers, algorithms, and I/O classes. You access its members with std:: prefix, e.g., std::cout, std::vector.
RAII (Resource Acquisition Is Initialization) ties resource lifetime to object lifetime:
Resources are acquired in the constructorResources are released in the destructorThis guarantees cleanup even if exceptions occur.
Flashcards
Flip to reveal
Focus Mode
Spaced repetition
Multiple Choice
Test your knowledge
Type Answer
Active recall
Learn Mode
Multi-round mastery
Match Game
Memory challenge