C++ Flashcards
C++ Show code for a mutex
static std::mutex mutex; std::lock_guard lock(mutex) // mutex automatically is unlocked when leaving function! Mutex // destructor does the unlocking!
Create a sample program to demonstrate semaphores.
#define SEMAPHORE_COUNT 10 sem_type semaphore;
sem_init (semaphore,0,SEMAPHORE_COUNT);
sem_wait(&semaphore); // do stuff sem_post(&semaphore); // free it
What is RAII?
Resource Acquisition is Initialization
Allocate a resource when it is needed, allocate when not. Acquire resources in the constructor, destroy in destructor.
What are the standard sequence containers in the c++ STL?
Vector, deque and list
What are the standard associative containers in c++ STL?
Set, multiset, map, multimap
C++: What does stringstream do, and what do you include?
include
A stringstream is a string that can be treated as a stream.
C: what preprocessor directives can you use to print out the function, file and line you are in?
__FUNCTION__
__LINE__
__FILE__
C++
Explain: class Complex : Number
Complex inherits Number.
HOWEVER! It inherits is such that all of number is private. What is probably meant is: class Complex : public Number