Advanced C++ Flashcards

1
Q

Assertion

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

auto

A
  • A keyword indicating that a variable gets its type from its initializer.
  • Can be used in place of the return type of function, but in this case the function must have a trailing return type
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is catch (…)?

A

Default exception

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Class Template

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Closure

A
  • An unnamed function object that stores the said function’s environment.
  • A runtime object created by a lambda expression.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the Const Data?

A
  • The const data area stores string literals and other data whose values are known at compile time. No objects of class type can exist in this area. All data in this area is available during the entire lifetime of the program.
  • Further, all of this data is read-only, and the results of trying to modify it are undefined. This is in part because even the underlying storage format is subject to arbitrary optimization by the implementation. For example, a particular compiler may store string literals in overlapping objects if it wants to.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Const Member Function

A
  • Declaring a member function with the const keyword specifies that the function is a “read-only” function that does not modify the object for which it is called. A constant member function cannot modify any non-static data members or call any member functions that aren’t constant.
  • To declare a constant member function, place the const keyword after the closing parenthesis of the argument list. The const keyword is required in both the declaration and the definition.
**class** **Date** { public: Date( int mn, int dy, int yr ); int getMonth() **const**; *// A read-only function*void setMonth( int mn ); *// A write function; can't be const*private:int month; }; int Date::getMonth() **const** { **return** month; *// Doesn't modify anything* } void Date::setMonth( int mn ) { month = mn; *// Modifies data member* } int main() { Date MyDate( 7, 4, 1998 ); **const** Date BirthDate( 1, 18, 1953 ); MyDate.setMonth( 4 ); *// Okay* BirthDate.getMonth(); *// Okay* BirthDate.setMonth( 4 ); *// C2662 Error* }
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

decltype

A
  • For deducing data-type from expression, or an auto variable.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

declval

A
  • Converts any type T to a reference type, making it possible to use member functions in decltype expressions without the need to go through constructors.
  • Commonly used in templates where acceptable template parameters may have no constructor in common, but have the same member function whose return type is needed. Note that because no definition exists for declval, it can only be used in unevaluated contexts; it is an error to evaluate an expression that contains this function.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is delete[]?

A

Deallocate storage space of array

#include *// std::cout***struct** MyClass { MyClass() {std::cout \<\<"MyClass constructed**\n**";} ~MyClass() {std::cout \<\<"MyClass destroyed**\n**";} }; void main () { MyClass\* pt = **new** MyClass[3]; **delete**[] pt; }
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Derived Classes

A
  • Runtime polymorphism, in C++, is provided by deriving classes from a base class that contains virtual functions.
  • The base class and virtual functions form the polymorphic prototype.
  • Code written to accept the base class that calls these virtual functions will accept any class instance derived from the base class.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Explain how C++ dynamic memory works

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Exception Handling

A
<small><span style="color: #BC7A00;">#include </span>
<span style="color: #008000; font-weight: bold;">using</span> <span style="color: #008000; font-weight: bold;">namespace</span> std;

<span style="color: #B00040;">int</span> <span style="color: #0000FF;">main</span> () {
  try
  {
    <span style="color: #008000; font-weight: bold;">throw</span> <span style="color: #666666;">20</span>;
  }
  <span style="color: #008000; font-weight: bold;">catch</span> (<span style="color: #B00040;">int</span> e)
  {
    cout <span style="color: #666666;">&lt;&lt;</span> <span style="color: #BA2121;">"An exception occurred. Exception Nr. "</span> <span style="color: #666666;">&lt;&lt;</span> e <span style="color: #666666;">&lt;&lt;</span> <span style="color: #BA2121;">'\n'</span>;
  }
  <span style="color: #008000; font-weight: bold;">return</span> <span style="color: #666666;">0</span>;
}
</small>
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Nested Exception Handling

A
try { try { **throw** std::runtime\_error("Test"); } **catch** (std::runtime\_error& e) { std::cerr \<\< "Inner Exception-Handler: " \<\< e.what() \<\< std::endl; **throw**; } } **catch** (std::exception& e) { std::cerr \<\< "Outer Exception-Handler: " \<\< e.what() \<\< std::endl; }

Will result in:

Inner Exception-Handler: Test Outer Exception-Handler: Test
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is the purpose of the explicit keyword?

A
  • To tell the compiler that a certain constructor may not be used to implicitly cast an expression to its class type.
  • The explicit keyword is an optional decoration for constructors that take exactly one argument. It only applies to single-argument constructors since those are the only constructors that can be used in type casting.

For example, without the explicit keyword the following code is valid:

**class** **Foo** { public: Foo(int x); }; **class** **Bar** { public: Bar(double x); }; void yourCode() { Foo a = 42; *//OK: calls Foo::Foo(int) passing 42 as an argument* Foo b(42); *//OK: calls Foo::Foo(int) passing 42 as an argument* Foo c = Foo(42); *//OK: calls Foo::Foo(int) passing 42 as an argument* Foo d = (Foo)42; *//OK: calls Foo::Foo(int) passing 42 as an argument* Bar x = 3.14; *//OK: calls Bar::Bar(double) passing 3.14 as an argument* Bar y(3.14); *//OK: calls Bar::Bar(double) passing 3.14 as an argument* Bar z = Bar(3.14); *//OK: calls Bar::Bar(double) passing 3.14 as an argument* Bar w = (Bar)3.14; *//OK: calls Bar::Bar(double) passing 3.14 as an argument* }

But sometimes you want to prevent this sort of implicit promotion or implicit type conversion. For example, if Foo is really an array-like container and 42 is the initial size, you might want to let your users say, Foo x(42); or perhaps Foo x = Foo(42);, but not just Foo x = 42;. If that’s the case, you should use the explicit keyword:

**class** **Foo** { public:**explicit** Foo(int x); }; **class** **Bar** { public:**explicit** Bar(double x); }; void yourCode() { Foo a = 42; *//Compile-time error: can't convert 42 to an object of type Foo* Foo b(42); *//OK: calls Foo::Foo(int) passing 42 as an argument* Foo c = Foo(42); *//OK: calls Foo::Foo(int) passing 42 as an argument* Foo d = (Foo)42; *//OK: calls Foo::Foo(int) passing 42 as an argument* Bar x = 3.14; *//Compile-time error: can't convert 3.14 to an object of type Bar* Bar y(3.14); *//OK: calls Bar::Bar(double) passing 3.14 as an argument* Bar z = Bar(3.14); *//OK: calls Bar::Bar(double) passing 3.14 as an argument* Bar w = (Bar)3.14; *//OK: calls Bar::Bar(double) passing 3.14 as an argument* }
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

extern

A

A keyword used to indicate that the definition of an entity being declared is defined elsewhere (i.e., another file).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

final

A

<small>Indicate that a derived class shall not override a virtual method.</small>

<small><span style="color: #008000; font-weight: bold;">class</span> <span style="color: #0000FF; font-weight: bold;">B</span> {
<span style="color: #A0A000;">public:</span>
  <span style="color: #008000; font-weight: bold;">virtual</span> <span style="color: #B00040;">void</span> f(<span style="color: #B00040;">short</span>) {std<span style="color: #666666;">::</span>cout <span style="color: #666666;">&lt;&lt;</span> <span style="color: #BA2121;">"B::f"</span> <span style="color: #666666;">&lt;&lt;</span> std<span style="color: #666666;">::</span>endl;}
};

<span style="color: #008000; font-weight: bold;">class</span> <span style="color: #0000FF; font-weight: bold;">D</span> <span style="color: #666666;">:</span> <span style="color: #008000; font-weight: bold;">public</span> B
{
  <span style="color: #A0A000;">public:</span> <span style="color: #008000; font-weight: bold;">virtual</span> <span style="color: #B00040;">void</span> f(<span style="color: #B00040;">int</span>) override final {std<span style="color: #666666;">::</span>cout <span style="color: #666666;">&lt;&lt;</span> <span style="color: #BA2121;">"D::f"</span> <span style="color: #666666;">&lt;&lt;</span> std<span style="color: #666666;">::</span>endl;}
};
</small>
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What is the Free Store?

A
  • The free store is one of the two dynamic memory areas, allocated/freed by new/delete.
  • Object lifetime can be less than the time the storage is allocated; that is, free store objects can have memory allocated without being immediately initialized, and can be destroyed without the memory being immediately deallocated.
  • During the period when the storage is allocated but outside the object’s lifetime, the storage may be accessed and manipulated through a void* but none of the proto-object’s nonstatic members or member functions may be accessed, have their addresses taken, or be otherwise manipulated.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

Function Object/Functor

A
  • Function objects can maintain state but require the syntactic overhead of a class definition.
  • For a basic problem, the simpler lambda design is probably better than the function-object design. However, if the functionality might require significant expansion in the future, then it is better to use function object design so that code maintenance will be easier.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

Function Pointer

A
**typedef** int(\*FunPtr)(int); int Square(int n) { **return** pow(n,2); } int Cube(int n) { **return** pow(n, 3); } void main(int argc, char \*argv[]) { FunPtr ptr; ptr = Square; cout \<\< ptr(2) \<\< endl; ptr = Cube; cout \<\< ptr(2) \<\< endl; }

Name of a function by itself, without parentheses, is a function pointer.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

Explain how function templates work

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

What is Global/Static?

A

Global or static variables and objects have their storage allocated at program startup, but may not be initialized until after the program has begun executing. For instance, a static variable in a function is initialized only the first time program execution passes through its definition. The order of initialization of global variables across translation units is not defined, and special care is needed to manage dependencies between global objects (including class statics). As always, uninitialized proto- objects’ storage may be accessed and manipulated through a void* but no nonstatic members or member functions may be used or referenced outside the object’s actual lifetime.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

Hash Map

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

What is a Hash Table?

A
  • Hash table is a data structure used to implement an associative array, a structure that can map keys to values.
  • A hash table uses a hash function to compute in index into an array of buckets or slots, from which the correct value can be found.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

What is the Heap?

A

The heap is the other dynamic memory area, allocated/freed by malloc/free and their variants. Note that while the default global new and delete might be implemented in terms of malloc and free by a particular compiler, the heap is not the same as free store and memory allocated in one area cannot be safely deallocated in the other. Memory allocated from the heap can be used for objects of class type by placement-new construction and explicit destruction. If so used, the notes about free store object lifetime apply similarly here.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

Increment and Decrement Operator Overloading

A

When the postfix increment and decrement appear in an expression, the corresponding user-defined function (operator++ or operator–) is called with an integer argument 0. Typically, it is implemented as T operator++(int), where the argument is ignored. The postfix increment and decrement operator is usually implemented in terms of the prefix version:

**class** **Point** { public: Point& **operator**++(); *// Prefix increment operator.* Point **operator**++(int); *// Postfix increment operator.**// Define default constructor.* Point() { x = 0; } private:int x; }; *// Define prefix increment operator.* Point& Point::**operator**++() { ++x;**return**\***this**; } *// Define postfix increment operator.* Point Point::**operator**++(int) { Point temp = \***this**; ++\***this**; or**operator**++();**return** temp; }
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
Q

What are different iterator types?

A
  • Input - reads forward​ (istream)
  • Output - writes forward (tream/inserter)
  • Forward - reads and writes foward
  • Bidirectional - reads and writes foward and backward (list/set/multiset/map/multimap)
  • Random access - reads and writes with radom access (vector/deque/string/array)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
27
Q

What is L”xxx”?

A

Wide string literal, represented as L”xxx”.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
28
Q

Lambda Declarator/Parameter List

A
29
Q

What are lambda expressions?

A
  • A lambda expression (also known as a lambda function) is nameless function defined at the place of call.
  • Exists only in a program’s source code. A lambda does not exist at runtime.
    <!-- HTML generated using hilite.me -->
[=] () **mutable** **throw**() -\> int {**return** x\*x;} sort(v.begin(), v.end(), [](**auto** a, **auto** b) { **return** a \> b; });
  1. lambda-introducer (Also known as the capture clause)
  2. lambda declarator (Also known as the parameter list)
  3. mutable (Also known as the mutable specification)
  4. exception-specification (Also known as the exception specification)
  5. trailing-return-type (Also known as the return type)
  6. compound-statement (Also known as the lambda body)
30
Q

Lambda-Introducer/Capture Clause

A

[=] () mutable throw() -> int

30
Q

std::map

A
31
Q
A
32
Q

What is a move constructor?

A

A move constructor of class T is a non-template constructor whose first parameter is T&&, const T&&, volatile T&&, or const volatile T&&, and either there are no other parameters, or the rest of the parameters all have default values.

*//C++11 brace-init*int a{ 0 }; string s{ "hello" }; string s2{ s }; *//copy construction* vector \<string\> vs{ "alpha", "beta", "gamma" }; map\<string, string\> stars{ { "Superman", "+1 (212) 545-7890" }, { "Batman", "+1 (212) 545-0987" } }; double \*pd = **new** double[3] {0.5, 1.2, 12.99}; **class** **C** { int x[4]; public: C() : x{ 0, 1, 2, 3 } {} };
34
Q

Mutable Data Members

A

This keyword can only be applied to non-static and non-const data members of a class. If a data member is declared mutable, then it is legal to assign a value to this data member from a const member function.

*// mutable.cpp***class** **X** { public:bool GetFlag() **const** { m\_accessCount++; **return** m\_flag; } private:bool m\_flag; **mutable** int m\_accessCount; }; int main() { }
34
Q

Multiple Inheritance

A

In a multiple-inheritance graph, the derived classes may have a number of direct base classes.

**class** **A** { **public**: void Foo() {} }; **class** **B** : **public** A {};
35
Q

nullptr

A

C++0x keyword for the null pointer. It is not an integer. It can be assigned only to pointers.

37
Q

Octet

A
  • A unit of digital information in computing and telecommunications that consists of eight bits.
  • The term is often used when the term byte might be ambiguous, as historically there was no standard definition for the size of the byte.
37
Q

What is the object slicing problem in C++?

A

Object slicing happens when a derived class object is assigned to a base class object, additional attributes of a derived class object are sliced off to form the base class object.

**class** **A** { int foo; }; **class** **B** : **public** A { int bar; };

So an object of type B has two data members, foo and bar

Then if you were to write this:

B b; A a = b;

Then the information in b about member bar is lost in a.

38
Q

override

A
  • Indicate that a method is supposed to be an override of a virtual method in a base class.
**class** **B** { public:**virtual** void f(short) {std::cout \<\< "B::f" \<\< std::endl;} }; **class** **D** : **public** B { public: **virtual** void f(int) override {std::cout \<\< "D::f" \<\< std::endl;} };
40
Q

Passing by Const Reference

A
  • Passes a large object to a function via a reference and prevents function of modifying the object.
void MyFunction(**const** BigObject& x) MyFunction(y); *// gives direct read-only access to y*
40
Q

pointer

A
  • A pointer is a variable that holds a memory address.
  • A pointer has its own memory address and size on the stack (4 bytes on x86).
  • You can have pointers to pointers to pointers offering extra levels of indirection.
  • Pointer can be assigned NULL directly.
  • Pointers can iterate over an array.
  • A pointer needs to be dereferenced with * to access the memory location it points to.
41
Q

What is a predicate?

A

The Predicate concept describes a function object that takes a single iterator argument that is dereferenced and used to return a value testable as a bool.

42
Q

Explain preprocessor

A
44
Q

What is a pure virtual function?

A
  • A pure virtual function or pure virtual method is a virtual function that is required to be implemented by a derived class if that class is not abstract.
  • Classes containing pure virtual methods are termed “abstract” and they cannot be instantiated directly.
  • A subclassof an abstract class can only be instantiated directly if all inherited pure virtual methods have been implemented by that class or a parent class.
  • Pure virtual methods typically have a declaration (signature) and no definition (implementation).
44
Q

Range-based for loops

A
  • C++11 augmented the for statement to support the “foreach” paradigm of iterating over collections.
  • In the new form, it is possible to iterate over C-like arrays, initializer lists and anything for which the non-member begin() and end()functions are overloaded.
**for**(**auto** v : kvp.second) { std::cout \<\< v \<\< std::endl; }
45
Q

reference

A
  • Must be assigned at initialization.
  • Cannot be re-assigned.
  • Shares the same memory address (with the original variable) but also takes up some space on the stack.
  • Only offer one level of indirection.
  • Example: type &newName = existingName;
46
Q

What is Resource Acquisition Is Initialization (RAII)?

A
47
Q

shared_ptr

A

shared_ptr is a smart pointer that retains shared ownership of an object through a pointer. Severalshared_ptr objects may own the same object. The object is destroyed and its memory deallocated when either of the following happens:

48
Q

What is the Stack?

A

The stack stores automatic variables. Typically allocation is much faster than for dynamic storage (heap or free store) because a memory allocation involves only pointer increment rather than more complex management. Objects are constructed immediately after memory is allocated and destroyed immediately before memory is deallocated, so there is no opportunity for programmers to directly manipulate allocated but uninitialized stack space (barring willful tampering using explicit dtors and placement new).

49
Q

static_assert

A

For compile time assertions. Useful for templates, and validations that cannot be done using #ifdef.

51
Q

What is std::make_shared?

A

Make shared_ptr

Allocates and constructs an object of type T passing args to its constructor, and returns an object of type shared_ptrthat owns and stores a pointer to it (with a use count of 1).

This function uses ::new to allocate storage for the object. A similar function, allocate_shared, accepts an allocator as argument and uses it to allocate the storage.

Tied to RAII concept.

51
Q

What is strongly typed?

A
52
Q

Templates

A
  • Templates are a feature of the C++ programming language that allow functions and classes to operate with generic types. This allows a function or class to work on many different data types without being rewritten for each one.
  • Templates provide compile-time polymorphism.
  • A template function or class can take any type which conforms to a prototype, usually called a “concept”

You can use templates to:

  • Create a typesafe collection class (for example, a stack) that can operate on data of any type.
  • Add extra type checking for functions that would otherwise take void pointers.
  • Encapsulate groups of operator overrides to modify type behavior (such as smart pointers).

Most of these uses can be implemented without templates; however, templates offer several advantages:

  • Templates are easier to write. You create only one generic version of your class or function instead of manually creating specializations.
  • Templates can be easier to understand, since they can provide a straightforward way of abstracting type information.
  • Templates are typesafe. Because the types that templates act upon are known at compile time, the compiler can perform type checking before errors occur.
53
Q

Trailing Return Type

A
  • A C++11 language construct that allows easier specification of a function return type through ‘decltype’ and the use of function parameter and class member names.
  • Trivial example: auto f() -> void;
**template****auto**AddThem(FirstType t1, SecondType t2) -\> decltype(t1 + t2) {**return** t1 + t2; }
54
Q

What is a translation unit?

A
55
Q

typename

A
  • An alternative to “class” when declaring template arguments; for example, “template void f(T);”
  • A way of telling a compiler that a name is meant to name a type in template code; for example “template void f(T a) { typename T::diff_type x = 0; … }”
56
Q

unique_ptr

A

Unique pointer

  • Manages the storage of a pointer, providing a limited garbage-collection facility, with little to no overhead over built-in pointers (depending on the deleter used).
  • These objects have the ability of taking ownership of a pointer: once they take ownership they manage the pointed object by becoming responsible for its deletion at some point.
  • unique_ptr objects automatically delete the object they manage (using a deleter) as soon as they themselves are destroyed, or as soon as their value changes either by an assignment operation or by an explicit call tounique_ptr::reset.
  • Exclusively owns object to which it points
  • Can’t be copied
  • Can be moved
  • make_unique
    <!-- HTML generated using hilite.me -->
#include #include **struct** Foo { Foo() { std::cout \<\< "Foo::Foo**\n**"; } ~Foo() { std::cout \<\< "Foo::~Foo**\n**"; } void bar() { std::cout \<\< "Foo::bar**\n**"; } }; void f(**const** Foo &) { std::cout \<\< "f(const Foo&)**\n**"; } int main() { std::unique\_ptr\<Foo\> p1(**new** Foo); *// p1 owns Foo***if** (p1) p1-\>bar(); { std::unique\_ptr\<Foo\> p2(std::move(p1)); *// now p2 owns Foo* f(\*p2); p1 = std::move(p2); *// ownership returns to p1* std::cout \<\< "destroying p2...**\n**"; } **if** (p1) p1-\>bar(); *// Foo instance is destroyed when p1 goes out of scope* }
57
Q

What is universal initialization?

A
  • Also called uniform initializtion.
  • Universal initializer is called a brace-init
58
Q

What is the benefit of using an unnamed/anonymous namespace?

A

When a local variable is defined without an anonymous namespace, if any other cpp files declares an extern int var;, it will be able to use the variable.

int var;

On the other hand, if a local variable is defined in an anonymous namespace, then at link time, the other cpp file wil generate an undefined reference error.

**namespace** { int var; }
59
Q

What is unwiding the stack?

A
60
Q

What are variadic templates?

A
61
Q

In the Debug version of MFC, evaluates its argument.

A

In the Debug version of MFC, evaluates its argument.

62
Q

Virtual Base Class

A

Virtual base classes, used in virtual inheritance, is a way of preventing multiple “instances” of a given class appearing in an inheritance hierarchy when using multiple inheritance.

**class** **A** { **public**: void Foo() {} }; **class** **B** : **public** **virtual** A {}; **class** **C** : **public** **virtual** A {}; **class** **D** : **public** B, **public** C {};
63
Q

Are there Virtual Constructors?

A

No

65
Q

What is a Virtual Destructor?

A

Ensures that the destructor for any class that derives from Base will be called when pointer to base class is deleted.

<small><span style="color: #BC7A00;">#include </span>
<span style="color: #008000; font-weight: bold;">using</span> <span style="color: #008000; font-weight: bold;">namespace</span> std;

<span style="color: #008000; font-weight: bold;">class</span> <span style="color: #0000FF; font-weight: bold;">Base</span>
{
<span style="color: #A0A000;">public:</span>
	Base() { cout <span style="color: #666666;">&lt;&lt;</span> <span style="color: #BA2121;">"Constructing Base"</span> <span style="color: #666666;">&lt;&lt;</span> endl; }
	<span style="color: #008000; font-weight: bold;">virtual</span> <span style="color: #666666;">~</span>Base() { cout <span style="color: #666666;">&lt;&lt;</span> <span style="color: #BA2121;">"Destroying Base"</span> <span style="color: #666666;">&lt;&lt;</span> endl; }
};

<span style="color: #008000; font-weight: bold;">class</span> <span style="color: #0000FF; font-weight: bold;">Derived</span> <span style="color: #666666;">:</span> <span style="color: #008000; font-weight: bold;">public</span> Base
{
<span style="color: #A0A000;">public:</span>
	Derived() { cout <span style="color: #666666;">&lt;&lt;</span> <span style="color: #BA2121;">"Constructing Derived"</span> <span style="color: #666666;">&lt;&lt;</span> endl; }
	<span style="color: #666666;">~</span>Derived() { cout <span style="color: #666666;">&lt;&lt;</span> <span style="color: #BA2121;">"Destroying Derived"</span> <span style="color: #666666;">&lt;&lt;</span> endl; }
};

<span style="color: #B00040;">void</span> <span style="color: #0000FF;">main</span>()
{
	Base <span style="color: #666666;">*</span>basePtr <span style="color: #666666;">=</span> <span style="color: #008000; font-weight: bold;">new</span> Derived();
	<span style="color: #008000; font-weight: bold;">delete</span> basePtr;
}
</small>
67
Q

Virtual Function Table

A
  • To implement virtual functions, C++ uses a special form of late binding known as the virtual table.
  • The virtual table is a lookup table of functions used to resolve function calls in a dynamic/late binding manner.
68
Q

Virtual Member Function

A
  • A member function that a derived class can override; the primary mechanism for run-time polymorphism in C++. A virtual member function is sometimes called a method.
  • Optional mechanism to mark virtual methods as overridden in derived classes.
69
Q

Void Pointer/void*

A
  • Used to indicate a pointer to anything
  • Any kind of pointer (char*, int*, Employee*, …) can be cast to it
    *
70
Q

Which operators cannot be overloaded in C++?

A
  • . (Member Access or Dot operator)
  • ?: (Ternary or Conditional Operator)
  • :: (Scope Resolution Operator)
  • .* (Pointer-to-member Operator)
  • sizeof (Object size Operator)
  • typeid (Object type Operator)