forked from chihyang/CPP_Primer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExer02_34.cpp
More file actions
38 lines (38 loc) · 1.01 KB
/
Copy pathExer02_34.cpp
File metadata and controls
38 lines (38 loc) · 1.01 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
// Warning: This is for verification. It cannot be compiled successfully by every compiler.
// The problem lies in line 29, 30, 31.
#include<iostream>
int main()
{
int i = 0, &r = i;
auto a = r;
const int ci = i, &cr = ci;
auto b = ci;
auto c = cr;
auto d = &i;
auto e = &ci;
const auto f = ci;
auto &g = ci;
const auto &j = 42;
std::cout << a << " " <<
b << " " <<
c << " " <<
d << " " <<
e << " " <<
g << " " << std::endl;
// Try to assign
// legal
a = 42;
b = 42;
c = 42;
// illegal
d = 42; // pointer, can't be assigned an int value
e = 42; // const pointer, here const is low-level because of &
g = 42; // const reference, const won't be ignored in this situation
std::cout << a << " " <<
b << " " <<
c << " " <<
d << " " <<
e << " " <<
g << " " << std::endl;
return 0;
}