Nested Classes and RAII Flashcards

1
Q

What is the first thing that is run when an instance of a class is created?

A

A class constructor

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

What are the two kind of special constructors in C++?

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

What is a copy constructor?

A

These constructors take an existing instance of a class and “deep” copy its resources into a new instance

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

What is a move constructor?

A

These constructors take an existing instance of a class and takes its resources for a new instance so that the original class no longer has them.

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

What is the call for a copy instructor (class A)

A

A(const A& other) {};

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

What is the call for a move instructor (class A)

A

A(A&& other) {};

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

How can we achieve creating move and copy functions?

A

Using operator overload.

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

What is the function call for copy assignment?

A

A& operator=(const A& other) {};

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

What is the function call for move assignment?

A

A& operator=(A&& toher) {};

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

What do classes model?

A

Model semantics and responsibilities or objects and their control of resources.

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

What can semantics always be simplified down to?

A

The “atomic” level. Members of classes can be other any type.
We use abstraction to make our life easier.

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

How many times should you implement a type?

A

A typed should be implemented once, so that it can be used everywhere else we need it. We shouldn’t have to worry about how we use it if it is implemented correctly.

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

What does RAII stand for?

A

Resource Acquisition Is Initialisation

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

What is RAII?

A

A programming technique is C++, the idea is the lifecycle of a resource must be acquired before used and released when the object is destroyed (constructors and destructors).
When an object is initialised we must obtain its resources.

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

What order does resource release happen in?

A

Reverse order to acquisition (FILO)

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

What does RAII require you to craft?

A

Code that ensures safety and stability.

17
Q

What is RAII in simple terms?

A

Writing our code in a way such that we acquire resources when initialising, and ensure that we release those resources at an appropriate time.

18
Q

What are memory leaks?

A

When a resource is never released