🌍 C++ Programming · flashcards
C++ Programming Object-Oriented Programming Flashcards
50 question-and-answer cards covering Object-Oriented Programming as it is examined in C++ Programming. 24 of them are printed below, taken from across the deck — no signup, no paywall on the preview.
24 sample cards from the Object-Oriented Programming deck
Sampled from the end of the deck, so these are different cards from the ones shown on the syllabus page.
What is compile-time (static) polymorphism and how is it achieved?
Compile-time polymorphism resolves the function call during compilation (early/static binding). It is achieved through function overloading and operator overloading (and templates).
What is function overloading?
Function overloading is defining multiple functions with the same name but different parameter lists (different number or types of parameters) in the same scope. The compiler selects the correct one based on the arguments. It is a form of compile-time polymorphism.
Can two functions be overloaded if they differ only in their return type?
No. Overloading requires differences in the parameter list (number, types, or order of parameters). Differing only by return type is not valid overloading and causes a compile error.
What is runtime (dynamic) polymorphism and how is it achieved?
Runtime polymorphism resolves the function call during execution (late/dynamic binding). It is achieved through virtual functions accessed via a base class pointer or reference, enabling function overriding.
What is the difference between function overloading and function overriding?
Overloading: same name, different parameters, same scope, resolved at compile time. Overriding: a derived class provides a new definition of a base class virtual function with the same signature, resolved at runtime via dynamic binding.
What is a virtual function?
A virtual function is a member function declared in a base class with the keyword virtual and redefined (overridden) in derived classes. It enables runtime polymorphism: the version called is determined by the actual object type, not the pointer/reference type.
What is a vtable (virtual table) and how does it enable dynamic dispatch?
A vtable is a per-class table of pointers to the class's virtual functions. Each polymorphic object holds a hidden vptr pointing to its class's vtable. At runtime, a virtual call is resolved by looking up the function address in the vtable via the vptr.
What is a pure virtual function and what is its syntax?
A pure virtual function is a virtual function with no implementation in the base class, declared by assigning $= 0$: $$\texttt{virtual void draw() = 0;}$$ It must be overridden by derived classes and makes its class abstract.
What is an abstract class in C++?
An abstract class is a class that contains at least one pure virtual function. It cannot be instantiated directly and serves as a base/interface; derived classes must override all pure virtual functions to become concrete (instantiable).
Can you create an object of an abstract class? Can you create a pointer or reference to it?
You cannot create (instantiate) an object of an abstract class. However, you can declare pointers and references to an abstract class, which are used to achieve polymorphism by pointing to derived-class objects.
Why should a base class intended for polymorphic use declare a virtual destructor?
So that deleting a derived object through a base-class pointer calls the derived destructor first, then the base destructor. Without a virtual destructor, only the base destructor runs, causing undefined behavior / resource leaks.
What is operator overloading and what is the general syntax of an operator function?
Operator overloading gives an operator a user-defined meaning for class operands. It uses a function named with the operator keyword: $$\texttt{returnType operator<op>(parameters);}$$ for example $\texttt{Complex operator+(const Complex\& rhs);}$
Name at least three operators that CANNOT be overloaded in C++.
The scope resolution operator $\texttt{::}$, member access operator $\texttt{.}$, pointer-to-member operator $\texttt{.*}$, the ternary conditional $\texttt{?:}$, and $\texttt{sizeof}$ cannot be overloaded.
What is unary operator overloading? Give an example operator.
Unary operator overloading redefines an operator that acts on a single operand, such as $\texttt{-}$ (negation), $\texttt{!}$, $\texttt{++}$, or $\texttt{--}$. Example: $\texttt{Point operator-();}$ negates the coordinates of a Point object.
How many arguments does a unary operator function take as (a) a member function and (b) a friend/global function?
(a) As a member function: zero explicit arguments (the operand is the invoking object, *this). (b) As a friend/global function: one argument (the single operand).
How are the prefix and postfix increment operators distinguished when overloading?
Prefix $\texttt{++obj}$ is overloaded as $\texttt{T operator++();}$. Postfix $\texttt{obj++}$ takes a dummy int parameter: $\texttt{T operator++(int);}$. The int argument is never used except to differentiate the two.
What is binary operator overloading? Give an example.
Binary operator overloading redefines an operator that works on two operands, such as $\texttt{+}$, $\texttt{-}$, $\texttt{==}$, $\texttt{<}$. Example: $\texttt{Complex operator+(const Complex\& b);}$ adds two Complex objects and returns their sum.
How many arguments does a binary operator function take as (a) a member function and (b) a friend/global function?
(a) As a member function: one argument (the right-hand operand; the left operand is *this). (b) As a friend/global function: two arguments (both operands explicitly).
When must a binary operator be overloaded as a friend/global function rather than a member function?
When the left-hand operand is not an object of the class (e.g., $\texttt{2 * obj}$ or $\texttt{cout << obj}$). A member operator requires the class object on the left, so a non-member (often friend) function is needed to allow a different left operand.
What is the function call operator and how is it overloaded?
The function call operator $\texttt{operator()}$ lets objects be called like functions (creating a functor). It is overloaded only as a member function and can take any number of arguments, e.g. $\texttt{int operator()(int x, int y);}$ enabling $\texttt{obj(a, b)}$.
What is a functor (function object) in C++?
A functor is an object of a class that overloads the function call operator $\texttt{operator()}$, so it can be invoked using function-call syntax like $\texttt{obj(args)}$. Functors can carry state and are widely used with STL algorithms.
Compare compile-time and runtime polymorphism on binding time and mechanism.
Compile-time: early/static binding, resolved at compilation, achieved via function/operator overloading; generally faster. Runtime: late/dynamic binding, resolved during execution via the vtable, achieved via virtual functions and overriding; more flexible but with slight overhead.
Why can a base class pointer point to a derived class object, and what determines which overridden function it calls?
Because a derived object 'is-a' base object (upcasting is implicit and safe). If the function is virtual, the actual (dynamic) type of the pointed-to object determines which override runs; if non-virtual, the static (pointer) type determines it.
What does the override specifier do in C++11 and why use it?
Placing override after a derived member function's signature (e.g. $\texttt{void draw() override;}$) tells the compiler the function is meant to override a base virtual function. If no matching virtual function exists, compilation fails, catching signature-mismatch bugs.
What this deck covers
The Object-Oriented Programming deck follows the C++ Programming Object-Oriented Programming syllabus — 5 chapters and 17 topics — so questions land on material that is genuinely examinable rather than trivia around it. That works out to roughly 10.0 cards per chapter.
Answers are written to be recallable, not just readable — averaging about 231 characters, which is long enough to carry the reasoning and short enough to say out loud.
A deck like this earns its keep on the second and third pass. Read the syllabus first so you know the shape of the subject, then use the cards to find the specific facts that have not stuck.
Object-Oriented Programming flashcards FAQ
How many Object-Oriented Programming flashcards are in this C++ Programming deck?
50 cards. This page previews 24 of them, sampled evenly across the deck so you can judge the difficulty before installing anything.
Are these C++ Programming flashcards free?
Yes. The preview here is free to read with no signup, and the full 50-card deck is free inside the Examius app.
What do the Object-Oriented Programming cards cover?
They follow the C++ Programming Object-Oriented Programming syllabus — 5 chapters and 17 topics — so the questions track what is actually examinable.
How should I use these flashcards?
Read the syllabus first so you know the shape of the subject, then drill the deck. Examius schedules each card with spaced repetition, so cards you keep missing come back sooner and ones you know drift further apart.