-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathc++11.txt
More file actions
60 lines (34 loc) · 1.23 KB
/
c++11.txt
File metadata and controls
60 lines (34 loc) · 1.23 KB
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
# c++11
The AUTO keyword can be used to make the compiler automatically deduce
the type of an object from its initializer.
Instead of: std::map<std::vector<unsigned long>, std::map<unsigned
short, long>>::const_iterator itr = map.begin()
Now use: auto itr = map.begin()
RANGE BASED FOR LOOPS are especially nice for iterating over containers:
std::vector<int> vec
for (auto itr : vec) { ++(*itr); }
The OVERRIDE identifier can be used to mark derived methods as overrides
of base class virtual functions. The FINAL identifier makes it
impossible for derived classes to implement a certain virtual method.
class A
{
public:
virtual void foo();
};
class B : public A
{
public:
virtual void foo() override final; // makes compiler know that this
is an override, will check for correct types; makes it impossible for
derived classes to override that method
};
class C : public B
{
public:
virtual void foo(); // Error! B marked foo() as final!
};
To set certain functions to their C++ default, use the DEFAULT keyword
after functions. E.g., for default constructors that you still want to
have defined (for smart pointers for example) but don’t want to have any
custom implementation:
~Foo() = default;