-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNotes.txt
70 lines (59 loc) · 3.1 KB
/
Notes.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
[typedef]:
==========
stands for “type definition”.
typedef is nothing but a way to assign a new name to a pre-existing data type.
In other words, typedef is basically a reserved keyword that we use in order to create an ("alias" name)
for a specific data type.
======================================================================================================================
[explicit]:
============
The explicit keyword in C++ is used to mark constructors to not implicitly convert types.
FROM STACKOVERFLOW:
-------------------
Suppose, you have a class String:
class String {
public:
String(int n); // allocate n bytes to the String object
String(const char *p); // initializes object with char *p
};
Now, if you try:
String mystring = 'x';
The character 'x' will be implicitly converted to int and then the String(int) constructor
will be called. But, this is not what the user might have intended.
So, to prevent such conditions, we shall define the constructor as explicit:
class String {
public:
explicit String (int n); //allocate n bytes
String(const char *p); // initialize object with string p
};
** In general:
single argument constructor must be marked as (explicit)
======================================================================================================================
[_allocator.allocate()]
=========================
Allocates storage suitable for an array object of type T[n] and creates the array,
but does not construct array elements.
May throw exceptions. If n == 0, the return value is unspecified.
======================================================================================================================
[_allocator.construct(&_array[i], val);]
=========================================
Constructs an object of type X in previously-allocated storage at the address pointed to by xp,
using args as the constructor arguments.
======================================================================================================================
[typename]
==========
When using a type from a template in some case, we should include (typename), cause the compiler will
be confused if we did not specify the type in some cases.
======================================================================================================================
[end()]:
========
the end() iterator (which is valid, but is not dereferenceable).
======================================================================================================================
[inline]:
When a function is marked as "inline", it means that the compiler should insert the function's body directly into
the code at the point of the function call, rather than generating a call to the function.
This can improve performance by avoiding the overhead of making a function call.
It's important to note that, the use of the inline keyword is a hint to the compiler, not a requirement.
The compiler may choose to ignore the hint and not inline the function,
depending on the context and the optimization settings.
The use of inline function is particularly useful when the function is small and is called frequently.