1.? ?
數(shù)組善涨,字符串蟹漓,結(jié)構(gòu)體聲明初始化可以使用大括號(hào)
double arr[4] {1.2, 3, 3.5, 5};
string thirdstr {“hello world”};
struct inflatable {
? string name;
flaot volume;
};
inflatable guest{“nihao”, 0.12};
2.? ? ?
新增std::array
std::array<int, 5> ai;
數(shù)據(jù)存儲(chǔ)在棧中膜钓,和int ai[5]一樣腔寡。
vector<int> ai 數(shù)據(jù)存儲(chǔ)在堆中忿磅,(new出的內(nèi)存)
3.? ?
基于范圍的for循環(huán)
std::vector<int> vc{ 6,7,8,9,10 };
for (intx : vc) {
? ? ? ? printf("%d\n", x);
}
for (auto & x : vc) { //引用的方式
? ? ? ? printf("%d\n", x);
}
循環(huán)數(shù)組似扔,容器類(array,vector,map等)
4.? ? ?
thread_loacl變量,每個(gè)線程擁有獨(dú)立的副本,不會(huì)相互影響屏轰。
5.? ?
auto 被用作類型推斷叨粘,不再當(dāng)做自動(dòng)變量答倡;register顯示的之處變量是自動(dòng)的,不再表明變量是寄存器存儲(chǔ),保留是為了兼容性渤涌。nullptr:新增空指針表示
6.? ?
類枚舉
enum class egg { Small, Medium, Large, Jumbo}
egg e = egg::Large
底層實(shí)現(xiàn)為int
7.? ? ?
智能指針:auto_ptr:賦值操作導(dǎo)致轉(zhuǎn)移指針?biāo)袡?quán)a=b,b丟失所有權(quán),再使用b將出錯(cuò)
share_ptr:賦值操作共享所有權(quán),通過(guò)引用計(jì)數(shù)方式管理內(nèi)存釋放
unique_ptr:編譯階段禁止賦值操作,臨時(shí)右值除外;當(dāng)需要轉(zhuǎn)移所有權(quán)時(shí),通過(guò)std::move來(lái)操作
8.
有序容器map,set等數(shù)據(jù)結(jié)構(gòu)用的紅黑樹(shù)樹(shù)蕉世,C++11中無(wú)序容器(unordered_set)用的hash
向楼?
9.
委托構(gòu)造函數(shù),將自己的構(gòu)造函數(shù)委托給其他構(gòu)造函數(shù)執(zhí)行初始化過(guò)程。
class A {
A(int)();
A(string, int):A("dd",int){}
}