OOP6 Polymorphism Flashcards

1
Q

What is function overloading?

A

The use of the same name for different functions, distinguished by their parameter lists

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

What is a generic algorithm?

A

An algorithm where a series of steps or operations are defined but the data type of the items being manipulated are not.

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

What is operator overloading?

A

Allows to redefine the standard C++ operators

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

What does typedef keyword do?

A

Defines a data type with a new user generated identifier

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

What is a generic data type?

A

A type for which the operations are defined but the data being manipulated is not

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

What is a class template?

A

A construct whereby the compiler may generate multiple versions of a class through parameterised data types

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

How to define a class template?

A

template <parameter>
Class Definition {};</parameter>

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

What is a template parameter?

A

A parameter that is used in the template definition

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

What is required type of a parameter template parameter?

A

class/typename

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

How to instantiate a new class from a template?

A

template<class>
class GList {…};

GList<int> intList;</int></class>

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

Newly instantiated classes from templates are called?

A

Generated classes, template classes

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

How can the relationship between a class template and template classes be defined?

A

A template class is a specialisation of the class template

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

What is a function template?

A

A construct that allows the compiler to generate multiple versions of a function according to allowing parameterised data types

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

How to define a function template?

A

template<class>
void GList<ItemType>::foo(ItemType i)
{…}</ItemType></class>

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

Template functions should use const reference parameters. Why?

A

Because they are much more efficient for memory

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

Const reference parameters for template functions ensure what?

A

That the object being oassed by const reference, will only allow its const functions (observer/accessor functions) to execute within the scope of this function

17
Q

How to instantiate a template function?

A

template<typename>
void Foo(ItemType i)
{…}

Foo<int>(i);</int></typename>

18
Q

The template argument of a function template is optional. True or false?

A

True

19
Q

How does the compiler know which template function to call with no template argument list?

A

It examines the type of the passed argument

20
Q

How to define an overloaded operator function?

A

returnType operator<(const itemType& comparatorItem) const
{…}

21
Q

How do overloaded operators compare two variables?

A

The first operand is the one on the left, the passed parameter is the second operand

22
Q

What operators cannot be overloaded?

A

sizeof(), ., ::, ?:

23
Q

How to overload a unary operator?

A

dataType operator-() const;

24
Q

What does the this keyword do?

A

This contains a pointer to whichever object that the function where this is called belongs to

25
Q

How can you refer to the actual object itself inside an object?

A

Dereference the this keyword, like so: *this

26
Q

What keyword is used for a function to prevent it from being overridden?

A

Final

27
Q

Early and late binding are other words for:

A

Static and dynamic binding

28
Q

Which are the only two types of member functions that can use dynamic binding/virtual keyword, and what cannot?

A

Ordinary members, destructors, NOT friend, static or constructors

29
Q

How is a pure virtual function defined?

A

It has no body, used in base class but must be overridden in the derived class, ended with = 0;,

30
Q

Destructor functions must be ___ if the object will be manipulated polymorphically

A

Virtual

31
Q

Why must polymorphic classes have virtual destructors?

A

The base class destructor might be called instead, producing undefined behaviour

32
Q

Pointer variables for base classes can accept pointers for which types?

A

The base class and any derived class