Enums and Structs Flashcards

1
Q

Program defined type / User defined type

give definition, examples and rules

A

A custom type we can create for use in our own programs.

The enumerated types and class types (including structs, classes and unions) allow for creation of program defined-types.

Program defined types must be defined before they are used

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

Type definition
Exempt from?

A

The definition of a program defined type. They are exempt from the one-definition rule

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

Enumeration / Enumerated Type / Enum

A

a compound data type where every possible value is defined as a symbolic constant

enumerations are distinct types, meaning the compiler can differentiate them from other types (unlike type aliases)

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

Name for the symbolic constants inside an enum

A

enumerator

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

Unscoped enumerations

A

they put their enumerator names in the same scope as the enumeration definition itself (as opposed to creating a new scope region like a namespace does).

Will implicitly convert to integral values

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

scoped enumerations

A

similar to unscoped enumerations but

won’t implicitly convert to integers

enumerators are only placed into the scope region of the enumeration (not into the scope region where the enumeration is defined)

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

struct

A

program defined data type that allows us to bundle multiple variables together in a single type.

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

data members / member variables

A

variables that are part of a struct or class

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

member selection operator

A

operator.

allows you to access a specific member variable for structs or refs to structs

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

member selection from pointer operator

A

operator->

allows you to access a specific member variable for pointers to structs

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

aggregate data type / aggregate

A

any type that can contain multiple data members

arrays and structs with only data members

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

aggregate initialisation

A

directly initialises members of aggregates with list of comma seperated values

e.g.

Triad t { 1, 2, 3 };

Initialises each member of the struct in order of declaration

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

memberwise initialization

A

each member in the struct is initialized in the order of declaration.

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

Designated initializers

Add a code example here

A

C++20

allow you to explicitly define which initialization values map to which members. The members must be initialized in the order in which they are declared in the struct, otherwise an error will result

Car myCar = { .make “Toyota”, .year = 2020 };

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

non-static member initialization

A

When we define a struct (or class) type, we can provide a default initialization value for each member as part of the type definition

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

default member initializer

A

name of default values passed to members in structs during non-static member initialization

17
Q

What will the compiler do to structs for performance

A

add padding. So the size of a structure may be larger than the sum of its members

18
Q

class template

A

a template definition for instantiating class types (structs, classes, or unions)

19
Q

Class template argument deduction (CTAD)

Needs code example

A

C++17 feature that allows the compiler to deduce the template type arguments from an initializer.