描述
C++ 默認構造函數std::list::list()構造一個具有零元素的空列表。
聲明
以下是 std::list::list() 構造函數形式 std::list 標頭的聲明。
C++98
explicit list (const allocator_type& alloc = allocator_type());
C++11
explicit list (const allocator_type& alloc = allocator_type());
參數
alloc─ 分配器對象。
這個分配器對象負責執行所有的內存分配。
返回值
構造函數從不返回值。
異常
此成員函數從不拋出異常。
時間複雜度
常數,即 O(1)
示例
以下示例顯示了 std::list::list() 構造函數的用法。
#include <iostream>
#include <list>
using namespace std;
int main(void) {
list<int> l;
cout << "Size of list = " << l.size() << endl;
return 0;
}
讓我們編譯並運行上麵的程序,這將產生以下結果——
Size of list = 0
相關用法
- C++ List list()用法及代碼示例
- C++ List cend()用法及代碼示例
- C++ List rbegin()用法及代碼示例
- C++ List remove_if()用法及代碼示例
- C++ List remove()用法及代碼示例
- C++ List crend()用法及代碼示例
- C++ List max_size()用法及代碼示例
- C++ List get_allocator()用法及代碼示例
- C++ List push_back()用法及代碼示例
- C++ List insert()用法及代碼示例
- C++ List empty()用法及代碼示例
- C++ List merge()用法及代碼示例
- C++ List erase_range()用法及代碼示例
- C++ List reverse()用法及代碼示例
- C++ List splice()用法及代碼示例
- C++ List begin()用法及代碼示例
- C++ List swap()用法及代碼示例
- C++ List unique()用法及代碼示例
- C++ List resize()用法及代碼示例
- C++ List assign()用法及代碼示例
注:本文由純淨天空篩選整理自 C++ List Library - list() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。