16. {
17. ProPoint pnt = pntList[i];
18. int id;
19. err = ProPointIdGet(pnt, &id);
20. CString cstr;
21. cstr.Format(TEXT("Point Id:
%d."), id);
22. AfxMessageBox(cstr);
23. }
24.
25. }
26. catch (exception& e)
27. {
28. AfxMessageBox(TEXT("exception."));
29. }
再贴上我封装的代码:
1、CProArray.h在前一篇博文<<类似vector的ProArray封装类CProArray>>中已贴出。
2、CProList.h
1.#ifndef _C_PRO_LIST_H_
2.#define _C_PRO_LIST_H_
3.
4.#include
5.#include "CProArray.h"
6.#include
7.#include
8.
9.using std:
:
exception;
10.using std:
:
out_of_range;
11.using std:
:
bad_alloc;
12.
13.template
14.class CProList
15.{
16.public:
17. CProList()
18. //throw(bad_alloc)
19. :
m_pArr(new CProArray())
20. {}
21.
22. CProList(const CProList& rhs)
23. :
m_pArr(rhs.m_pArr)
24. {
25. ++(m_pArr->use);
26. }
27.
28. CProList& operator=(const CProList& rhs)
29. {
30. if (--(m_pArr->use) == 0)
31. delete m_pArr;
32. ++(rhs.m_pArr->use);
33. m_pArr = rhs.m_pArr;
34. }
35.
36. ~CProList()
37. {
38. if (--(m_pArr->use) == 0)
39. delete m_pArr;
40. }
41.
42.public:
43. size_t size() const
44. {
45. return m_pArr->size();
46. }
47.
48. bool is_empty() const
49. {
50. return m_pArr->is_empty();
51. }
52.
53. void clear()
54. {
55. m_pArr->clear();
56. }
57.
58. void push_back(const TYPE& val)
59. {
60. m_pArr->push_back(val);
61. }
62.
63. void pop_back()
64. {
65. m_pArr->pop_back();
66. }
67.
68. const TYPE& front() const
69. //throw(out_of_range)
70. {
71. try
72. {
73. return m_pArr->front();
74. }
75. catch (const out_of_range&)
76. {
77. throw out_of_range("empty CProList.");
78. }
79. catch (...)
80. {
81. throw;
82. }
83. }
84.
85. TYPE& front()
86. //throw(out_of_range)
87. {
88. return const_cast(const_cast(this)->front());
89. }
90.
91. const TYPE& back() const
92. //throw(out_of_range)
93. {
94. try
95. {
96. return m_pArr->back();
97. }
98. catch (const out_of_range&)
99. {
100. throw out_of_range("empty CProList.");
101. }
102. catch (...)
103. {
104. throw;
105. }
106. }
107.
108. TYPE& back()
109. //throw(out_of_range)
110. {
111. return const_cast(const_cast(this)->back());
112. }
113.
114. const TYPE& operator[](size_t index) const
115. //throw(out_of_range)
116. {
117. if (is_empty())
118. throw out_of_range("empty CProList.");
119. try
120. {
121. return m_pArr->operator[](index);
122. }
123. catch (const out_of_range&)
124. {
125. throw out_of_range("invalid index of CProList.");
126. }
127. catch (...)
128. {
129. throw;
130. }
131. }
132.
133. TYPE& operator[](size_t index)
134. //throw(out_of_range)
135. {
136. return const_cast(const_cast(this)->operator[](index));
137. }
138.
139. const TYPE& at(size_t index) const
140.