C11-noexcept

SHOW_SMALL_FUNCTION_BLOCK_TIPS("noexcept")
	{
		//關鍵字跟在函數後面,意思是不拋出異常
		//正常情況下,vector如果在你自定義類對象增加時自增長,那麼調用你的默認拷貝構造函數。
		//如果你要進行優化在vextor的自增長時使用右值引用(移動)的構造函數
		//那你就需要寫一個這個函數,這個函數優先級比較高,會優先調用
		//vector成長時會調用
		class Test
				{
			int a = 0;
			int b = 0;
				public:
					Test()
					{}
					Test(Test&& test)noexcept
					{
						cout << "Test(Test&& test)noexcept" << endl;
					}
					~Test()
					{}

				private:

				};
		vector<Test> t;
		cout << "加入1個" << endl;
		t.push_back(Test());
		cout << "加入1個" << endl;
		t.push_back(Test());
		cout << "加入1個" << endl;
		t.push_back(Test());
		cout << "加入1個" << endl;
		t.push_back(Test());
		cout << "加入1個" << endl;
		t.push_back(Test());
		cout << "加入1個" << endl;
		t.push_back(Test());
		
		//cout << typeid(decltype(t)::value_type).name() << endl;

	}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章