C++ Flashcards

0
Q

C++ Show code for a mutex

A
static std::mutex mutex;
std::lock_guard lock(mutex)
// mutex automatically is unlocked when leaving function! Mutex
// destructor does the unlocking!
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
1
Q

Create a sample program to demonstrate semaphores.

A
#define SEMAPHORE_COUNT 10
sem_type semaphore;

sem_init (semaphore,0,SEMAPHORE_COUNT);

sem_wait(&semaphore); 
// do stuff
sem_post(&semaphore); // free it
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is RAII?

A

Resource Acquisition is Initialization

Allocate a resource when it is needed, allocate when not. Acquire resources in the constructor, destroy in destructor.

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

What are the standard sequence containers in the c++ STL?

A

Vector, deque and list

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

What are the standard associative containers in c++ STL?

A

Set, multiset, map, multimap

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

C++: What does stringstream do, and what do you include?

A

include

A stringstream is a string that can be treated as a stream.

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

C: what preprocessor directives can you use to print out the function, file and line you are in?

A

__FUNCTION__
__LINE__
__FILE__

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

C++

Explain:
class Complex : Number
A

Complex inherits Number.

HOWEVER! It inherits is such that all of number is private. What is probably meant is:
class Complex : public Number
How well did you know this?
1
Not at all
2
3
4
5
Perfectly