cpp1 Flashcards

1
Q

how to read variable types?

A
  1. start reading at the variable’s name
  2. read as far as possible until you reach the end of the declaration or
    an (as yet unmatched) closing parenthesis.
  3. return to the point where you started reading, and read backwards
    until you reach the beginning of the declaration or a matching opening
    parenthesis.
  4. If you reached an opening parenthesis, continue at step 2 beyond the
    parenthesis where you previously stopped.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

als je een reference in een functie wil hebben naar een variable in main dan doe je:

A

void increase(int &valr) // expects a reference
{ // to an int
valr += 5;
}
increase(x);

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

how do you call a double array to a function?

A

Double array in parameters[][80] de 2e is belangrijk de eerste niet. Want de 2e is de grootte van hie ver de volgende pointer verder moet zijn dan de vorige.

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

welke casts?

A

static cast
const cast
reinterpret cast

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

what does ios do?

A

inherits from ios_base and additionally implements communications with a buffer used by streams.

it thus uses streambuf object

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

how to return mutiple things from funtcion?

A

use a structured binding declaration such as: struct, tuple, pair

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

make a function not accepting any arguments

A

function(void)

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

ifndef is an

A

include guard

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

how to prevent this backdoor?

string &Person::name() const
{
return d_name;
}

Person somebody;
somebody.setName("Nemo");

somebody.name() = "Eve";    // Oops, backdoor changing the name
A

return a const string & ipv string &

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

ambiguity resolution

A
  • More in general: when possible the compiler will interpret a syntactic construction as a declaration, rather than as a definition (of an object or variable).
  • Most problems that result from the compiler interpreting constructions as declarations are caused by us using parentheses. As a rule of thumb: use curly braces, rather than parentheses when constructing objects (or values)
Type object{ value list };
Fun(fun); //making an anonymous object often doesnt work
//it parses it as Fun fun which is the definition of fun using a 
//constructor without arguments.
//however:
Fun{fun} can be done
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

what member function is always preferred?

A

a const member function

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

how are references and pointers related

A

references are const pointers but no indirection takes place

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

To cast an object to an rvalue reference

A

use move semantics (e.g.

std::move(obj))

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

diff array and pointer

A

The name of an array is a pointer to its begin
location in memory.
A main difference between arrays and pointers is that an array is an rvalue, whereas a pointer is an
lvalue.

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

const komt

A

DIRECT na datgene wat const is. dus *const is een const pointer maar **const is een const pointer naar een pointer (of array).

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