Types, init & References
Uniform initialization, auto, structured bindings, lvalue/rvalue references.
Key PointsPrefer {} initialization and auto; understand lvalue vs rvalue before learning move semantics.
C++
#include <iostream>
#include <string>
int main() {
int a{42}; // uniform init, no narrowing
auto s = std::string{"cpp"}; // deduced type
auto [x, y] = std::pair{1, 2}; // structured bindings (C++17)
int& ref = a; // lvalue reference
ref = 7;
std::cout << a; // 7
}Narrowing conversions like int x{3.5} are rejected by brace init.
C++
#include <iostream>
#include <string>
int main() {
int a{42}; // uniform init, no narrowing
auto s = std::string{"cpp"}; // deduced type
auto [x, y] = std::pair{1, 2}; // structured bindings (C++17)
int& ref = a; // lvalue reference
ref = 7;
std::cout << a; // 7
}大括号初始化会拒绝 int x{3.5} 这类收窄转换。