Function Overloading and Function Templates Flashcards

1
Q

Function Overloading

A

allows us to create multiple function with the same name, so long as they have a different set of parameter inputs or types

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

How does the compiler match a call to an overloaded function?

(called Overload Resolution)

A

First it will look for an exact match

If this cannot be found it will favour numeric promotion

If this cannot be found it will do numeric conversion

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

Ambiguous match

A

when the compiler finds two or more functions that can match a call to an overloaded function. This will cause an error

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

where must a default argument be placed

A

must always be the rightmost parameter

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

Function template

A

allows us to create a function like definition that serves as a pattern for creating related functions

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

Type template parameters

A

placeholders for types we want to be specified later.

Used in function templates

e.g. template < typename T >

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

Template argument deduction

Define.
What don’t they do.

A

allows the compiler to deduce the actual type that should be used to instantiate a function from the arguments of the function call

Template argument deduction does not do type conversions

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

Generic types / Generic programming

A

Another name for template types and programming using templates

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

abbreviated function template

(Give code example)

A

using auto as the parameter type

auto max(auto x, auto y)
{
return (x < y) ? y : x;
}

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

non-type template parameter

A

a template parameter with a fixed type that serves as a placeholder for a constexpr value passed in as a template argument.

template <int> // declare a non-type template parameter of type int named N
void print()
{
std::cout << N << '\n'; // use value of N here
}</int>

int main()
{
print<5>(); // 5 is our non-type template argument

return 0; }
How well did you know this?
1
Not at all
2
3
4
5
Perfectly