[問題] allocator
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
VC++
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
None
問題(Question):
Allocator的作用是??
程式碼(Code):(請善用置底文網頁, 記得排版)
#include <list>
#include <iostream>
using namespace std;
#if _MSC_VER > 1020 // if VC++ version is > 4.2
using namespace std; // std c++ libs implemented in std
#endif
typedef list<int, allocator<int> LISTINT;
void main()
{
int rgTest1[] = {5,6,7};
int rgTest2[] = {10,11,12};
LISTINT listInt;
LISTINT listAnother;
LISTINT::iterator i;
// Insert one at a time
listInt.insert (listInt.begin(), 2);
listInt.insert (listInt.begin(), 1);
listInt.insert (listInt.end(), 3);
// 1 2 3
for (i = listInt.begin(); i != listInt.end(); ++i)
cout << *i << " ";
cout << endl;
// Insert 3 fours
listInt.insert (listInt.end(), 3, 4);
// 1 2 3 4 4 4
for (i = listInt.begin(); i != listInt.end(); ++i)
cout << *i << " ";
cout << endl;
// Insert an array in there
listInt.insert (listInt.end(), rgTest1, rgTest1 + 3);
// 1 2 3 4 4 4 5 6 7
for (i = listInt.begin(); i != listInt.end(); ++i)
cout << *i << " ";
cout << endl;
// Insert another LISTINT
listAnother.insert (listAnother.begin(), rgTest2, rgTest2+3);
listInt.insert (listInt.end(), listAnother.begin(),
listAnother.end());
// 1 2 3 4 4 4 5 6 7 10 11 12
for (i = listInt.begin(); i != listInt.end(); ++i)
cout << *i << " ";
補充說明(Supplement):
其實我只是想要問 typedef list<int, allocator<int> LISTINT;
這行中的allocator<int>這個的用意???
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 36.239.251.183
→
11/23 02:06, , 1F
11/23 02:06, 1F
→
11/23 02:51, , 2F
11/23 02:51, 2F
→
11/23 02:52, , 3F
11/23 02:52, 3F
→
11/23 02:52, , 4F
11/23 02:52, 4F
→
11/23 02:53, , 5F
11/23 02:53, 5F
→
11/23 02:53, , 6F
11/23 02:53, 6F
→
11/23 10:11, , 7F
11/23 10:11, 7F
→
11/23 10:13, , 8F
11/23 10:13, 8F
→
11/23 10:13, , 9F
11/23 10:13, 9F
→
11/24 01:47, , 10F
11/24 01:47, 10F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章