ºÝºÝߣ

ºÝºÝߣShare a Scribd company logo
7-41. ??? ?????? ???? ??? ?????? ??? ?? ?????
? ?? ?? ??? ?? ? w? swap, normalize, !=???, > ???
?? ????? ??? ????? ??? ???. ??? w? ??
??? ?????? ??.
? ?? ? ??? w? ?? ??? ? ? ???? ??????
?????, T? ?? ????? ?? ?? ??? ?????? ?
?????? ???? ??? ??? ????. ??? ??? ??
???????.
7-41. ??? ?????? ???? ??? ?????? ??? ?? ?????
? ??? ?? ?? ??? ??? ??? ?? ?? ?? ??? ? ??
?????? ??? ?????? ??.
? ?? ? ???? ??? ????? ??? ? ?? ??? ???
???? ?? ?? ???? ?? ?? ????. ??? ??? ???
?????? ??.
7-42. typename? ? ?? ??? ??? ????
? ??? ?? ???? ?????
iterator? ???? T????
?? ???? ? ?? ??.
? ??? ????? ?? ?? ??
??? ????.
? ?????? iterator????
????? ???? ??? ??
typename? ????? ??.
????? template<class T>? template<typename T>? ??? ??.
?? ??? ?? ?? typename? ????.
7-42. typename? ? ?? ??? ??? ????
? std::iterator_traits<T>::value_type?? T??? ??? ????
??? ????? ????.
? ?, T??? ??? ???? ??? ?? ??? temp? ????
iter? ???? ??? temp? ??? ???.
? ???¡­ std::iterator_traits<T>::value_type ¡­? ??.
?? ? ???? ?? ??? ?? ??? ?? typedef? ??.
typedef typename std::iterator_traits<T>::value_type value_type;
value_type temp( *iter );
7-43. ????? ???? ?? ??? ?? ??? ???? ??? ?? ??
??? ?? ???? ??? ??.
2?? ???? ??? ???? ???.
????? Derived? ???? ?
Tclass? ??? ?? Base? ????
??? ? ??? ?? ????.
????? 3??? ??.
7-43. ????? ???? ?? ??? ?? ??? ???? ??? ?? ??
???? 3??? ??? ??
? Func1() ?? this->Func1()? ????.
??? ??? Func1()? ???? ??? ?????.
? Func1()?? ?? using Base<Tclass>::Func1;? ??????
Func1()??? ??? ?????.
? Base<Tclass>::Func1();? ???? ??? ???? ?????.
?? ? ??? ???? ???? ????? ???? ???.
7-43. ????? ???? ?? ??? ?? ??? ???? ??? ?? ??
¡ù??
??? ???? ? ?? ????
????
??? ?? ??? ?? ???
???? ??? ???
Func1()? ???? ???? ???
??? ?? ??.
7-44. ????? ???? ??? ??????? ?????
??? ??? ??? ?? ??? ????? ? ?? ?? ?? ??,
??? ? ??? ???? ???? ??? ???.
??? ?? n??? ?????
??? ??? ???? ??? ??.
??? 5x5?? 10x10??? ???
???? SquareMatrix????
2?? ??? ??.
7-44. ????? ???? ??? ??????? ?????
? ? ?????
??? 2? ?????
??? 5, 10? ???
?? ??? ???
??? ??? ???
?? ???? ??.
??? ?? n??
???? ?????
???? ??? ??
??? ??? ? ??.
7-44. ????? ???? ??? ??????? ?????
??? ? ? ????
??? ???. invert ???
?? ?? ??? ??
?????? ??? ??
??? ?? ???? ??
??.
??? ????? ???
?? ???????
?????? ????
???? ????? ??.
7-44. ????? ???? ??? ??????? ?????
¡ù??
???? ??? ??? ???? ??? ??? ????? ???
??? ??? ?? ? ? ??.
??, ???? ?? ??? ??? ???? ??? ?? ????
???? ???? ??? ??? ????? ??? ?? ???
??? ?? ? ???? ??? ?? ????.
7-45. ¡°???? ?? ??¡±? ????? ?? ?? ?? ???? ??!
?? ?? ???? ???? ??, ?????? ???? ??????
???? ??? ??? ????.
?? ?? ???? ?????? ??? ???? ????.
??? ?? ???? ?? ? ??? ??? ??? ???? ?????
??? ??? ??? ?????.
?? ?? ??? ???? ???? ??.
7-45. ¡°???? ?? ??¡±? ????? ?? ?? ?? ???? ??!
??? ?? ?? ???
???? ?? ?? ??
???? ??? ??? ???
U?? ???? T?? ????
??? ?? ??? ??? ?
?? ?? ? ??.
???? ??? ?? ????
?? ?? ???? ???
??? ? ??? ?????.
7-46. ?? ??? ???? ???? ??? ??? ??? ??? ?? ??? ??
??? ??? ??? ? ???
????? ?? ????
24???? ?? ?????
?? ??? ???? ???
????.
Rational<int> oneHalf( 1, 2 );
Rational<int> result = oneHalf * 2;
??? ?? ???? 2??
?? 2? ?? ??? ?? ??
??? ??.
7-46. ?? ??? ???? ???? ??? ??? ??? ??? ?? ??? ??
?? ?? ??? ?? friend? ????? ????? ?? ???? ??.
??? ???? ?? ?? ??? ?? ?? ??? ?? ??? ??.
??? ??? ?? ?? ??? ??? inline????? ?? ??
?? ??? ??? ???? ??? ???? ???? ??.
7-47. ??? ?? ??? ????? ???? ???? ????
???? ??? ???? ?? ??? ??? ????? ??.
?? ???? 5?? ??? ??, ?? ???? ?? ?? ???? ??.
input_iterator_tag : ?? ???. ????? 1? ?? ? ??? ????.
output_iterator_tag : ?? ???. ????? 1? ?? ? ??? ????.
forward_iterator_tag : ??? ???. ?? ???? ????.
??? ???? ?? ? ????.
bidirectinal_iterator_tag : ??? ???. ??? ???? ????.
??? ???? ?? ? ????.
random_access_iterator_tag : ?? ?? ???. ??? ???? ????.
????? ??? ?? ??, ???? ?? ? ????.
7-47. ??? ?? ??? ????? ???? ???? ????
??? ??? ??? ?? ??? ?? ?? iterator_traits ?? ???
???? ?? ? ??. ??? ?? ??? ???? ???? ?? ????
???? ?? ?? ???? ???.
??? ????? typedef? ??? ??? ?? iterator_category?
????. (vector??? ?? ?? ?????.)
7-47. ??? ?? ??? ????? ???? ???? ????
Iterator_traits??? ?? ??? ??? ??? iterator_category? ???
????.
?? ??? ???? ???? ??? ??? ?? ?? ???? ????
??? ?? ???? ???.
7-47. ??? ?? ??? ????? ???? ???? ????
?? ?? ??? ??? ???. ?? ???? ??? ??? ?? ???.
??? ? ??? ???? ??? ???? ?? ?,
??? ?? ??? ??? ??? ??.
7-47. ??? ?? ??? ????? ???? ???? ????
C++?? TR1?? ?? ?? ?? ?? ???? 50? ???.
( ex> is_array<T>, is_base_of<T1, T2>, ?? )
??? ?? ??? ??? ??? ??? ?? ???? ??? ?? ??
?? ?? ???? ?? ?? ??? ?? ???? ?????? ? ????
??? ??? ???? ? ??.
7-48. ??? ???????, ?? ?????
??? ?? ?????(TMP)? ??? ????? ?? ??? ???
???? ??? ? ??? ?? ??? ??.
??? ?? ?? ?? ????? ?? ? ??? ??? ???? ????
?? ????,
????? ?? ? ??? ??? ???? ??? ??? ????
??????? ??? ??? ??? ????? ?? ????.
(¡ù?? ?? ?? ??? ??? ???? ??.)
7-48. ??? ???????, ?? ?????
?? ?? ???? ?? ???? ?? ? TMP? ???? ??? ??.
?? ?? ???
??? ????
?? ?? ???
?? ?? ??
??? ???? ??.
7-48. ??? ???????, ?? ?????
TMP? ??? ?? ??? ??? ? ??.
? ??(??, ??, ?? ?)? ??? ??
?? ?? ??? ??????? ??? ?? ??? ??? ??? ??.
TMP? ?? ??? ???? ???? ? ??.
? ?? ??? ???
? ??? ??? ?? ??? ??
typedef SquareMatrix<double, 10000> BigMatrix;
BigMatrix m1, m2, m3, m4, m5;
...
BigMatrix result = m1 * m2 * m3 * m4 * m5;
??? ??? ?????
??? ?? ?? ????
?? ??? ???? ????
??? ??? ? ? ??.
8-49. new ???? ?? ??? ??? ????
new???? ??? ??? ???? ? ??? ??? ?? ???? ???
new_handler?? ??, ?? ???? ??(??) ????.
set_new_handler??? ???? ? ??? ??? new_handler? ????
?? ??? ?? ?? new_handler? ????.
new_handler?? ??? ?? ??? ?? ? ??.
? ??? ? ?? ???? ? ????.
? ??? ??? ? ?? ?? new ???? ????.
? ??? new ???? ???? ??? ??? ??.
? bad_alloc?? ??? ??? ??? ??? ??? ?? ??? ????.
? ???? ?? ??? abort? exit ?? ????.
8-49. new ???? ?? ??? ??? ????
?? ?? ????
??? ?????
?? ??? ?
set_new_handler?
??? ? ??.
??? ???
??? ?????
?? ????
??? ????
??? CRTP??
??.
¡ù CRTP : Curiously Recurring Template Pattern
8-49. new ???? ?? ??? ??? ????
1993???? new? ??? ??? ?? ? null???? ?? ??? ? ?
? ??? bad_alloc ??? ???? ???. ??? ?? null??? ???
???? ??? ????? ???? ? ??? ?? ??? ??? ??.
??? null???? ???? ? ??? ¡°????(nothrow)¡± ???? ??.
class Widget { ... };
Widget *pw = new ( std::nothrow ) Widget;
if( pw == nullptr ){ ... }
??? ??? ????.
?? ??? ???? ???
????? ?? ?? ?? ?? ??
new?? ??? ??? ???.
8-50. new ? delete? ?? ??? ?? ??? ???? ??? ??
operator new? operator delete? ???? ??? ?? 3??? ???.
? ??? ? ??? ????.
- new? ??? ??? ??? ?? ? delete? ??? ?????
delete? ????? ?? delete ?? ??? ?? ? ??.
- ?? ??? ??? ?? ???/??? ??? ??? ?? ????? ?
? ? ??.
? ??? ?????.
- ?? ???? new? ??? ????? ????? ????? ???.
???? ???? ????? ??? ??? ??.
? ?? ?? ???? ?? ?? ??? ????.
8-50. new ? delete? ?? ??? ?? ??? ???? ??? ??
??? ??? ?? ????? ???.
? ?? ??? ???? ?? ????? ???.
? ??? ??? ?? ???? ??? ?? ??? ????.
- ?? ?? ????? double ?? ?? ? 8??? ??? ???? ??
??? ??. ?? ?? new? ???? ?? ??? ?? ? ??.
? ??? ??? ?? ?? ???? ? ?? ?????.
- ?? ?? ??? ?? ?????? ??? ?? ?? new/delete?
???? ?? page? ?? page fault? ??? ? ? ??.
? ???? ??? ??? ????? ??.
- ?? new/delete? ???? ?? ??? ???? ?? ??
¡ù ???? ??, ???? ??? ?? ????? ???? ?? ????? ????.
8-51. new ? delete? ??? ? ??? ? ??? ??? ? ?? ??
new
? ?? ?? ??? ?? ?? ?
- ?? ?? ?? ???? ???? ?.
- ?? ??? ??? new ???? ?? ?? ??? ??? ?????.
- new? new ??? ???? null? ???? bad_alloc??? ???.
? ?? ???? ???? new ??? ??? ??? ?
? ??? ??(0 byte) ??? ??? ???? ?? ?
? ?? ??? new? ???? ??? ? ?
? ?? ???? ?? ?? ???? new? ???? ??? ??? ??? ?
???? ???? ????.
- ?? ??? ???? ??? ??? ??? ?? ???? new? ??.
8-51. new ? delete? ??? ? ??? ? ??? ??? ? ?? ??
delete
? null???? ?? delete? ??? ????.
? ??? ???? ??? ?????.
- ?? ?? ??? ???? ??? ??? ?? ?? ?? delete? ??.
8-52. ???? new? ????? ???? delete? ?? ????
?? ?? ???? ??? ?? new? ???? ???? ?????
Widget ????? ??? ??? ?? C++??? ????? delete?
???? ??.
?? ??? ???? ?? new? ?? ?? delete? ???? ????
???? ?? ??? ??? ????.
??? ??? ????? ???? ? ? delete ??? ??? ???
delete? ????.
?, ???? new? ?? ??? ??? delete? ???? delete? ??
??? ??? ??.
Widget *pw = new (std::cerr) Widget;
8-53. ???? ??? ???? ??
??(warning) ???? ????? ? ??. ????? ??? ????
??? ? ???? ?? ??.
?? ??? ??
Warning: Derived::Func() hides virtual Base::Func()
?? ??? ??.
?? ??? ??? ????? ???
const? ????? ????? ???
????? ???? ?? ???.
¡ù??
?? ???? ????? ?? ??????. ???? ????? ???.
8-54. TR1? ??? ?? ????? ????? ??? ??? ??
C++98? ?? C++?????? ?? ?? ??? ??? ??.
? ?? ??? ?????(STL: Standard Template Library)
? iostream : ??? ?? ???, ??? ?? ???, cin, cout, cerr ?.
? ??? ?? : ?? ???(locale)? ????(wchar_t, wstring) ??.
? ?? ?? ??: ??? ???(complex), ???? ???(valarray)?.
? ?? ??? : exception ? logic_error, runtime_error ?.
? C89? ?? ?????
?? ???? ?? ???? ??.
8-54. TR1? ??? ?? ????? ????? ??? ??? ??
TR1? ???.
? ??? ??? : shared_ptr? ?? ??? ??? ?? ???? 0? ??
? ??. weak_ptr? ?? ??? ?????.
? tr1::function : ?? ??? ????? ???? ????? ?? ????
??? ????.
?? ???? ????? ¡°int? ?? string? ???? ??¡±?? ????.
? tr1::bind : STL? bind1st, bind2nd? ?? ??? ?? ?? ??
??? ????. ??? ??? ??? ?? ?? ??????, ?? ??
??? ?? ???? ?? ? ??.
void regCallBack( std::string func( int ) );
void regCallBack( std::string ( int ) );
8-54. TR1? ??? ?? ????? ????? ??? ??? ??
? ?? ??? : ?? ???? ???? ??, ?, ????? ?????.
tr1::unordered_set, tr1::unordered_multiset,
tr1::unordered_map, tr1::unordered_multimap.
? ?? ??? : ?? ??? ??? ??, ?? ???? ?????.
? ?? : pair? ????? 2??? ? ??? ?? ? ??.
? tr1::array : ¡°STL??? ?¡± ??.
? tr1::mem_fn : ?? ?? ???? adapt??? ??. mem_fun,
mem_fun_ref ?? ???.
? tr1::reference_wrapper : ??? ???? ???? ?? ? ?? ???.
? ?? ?? : ?? rand? ???.
? ?? ??? ?? ?? : ??? ???, ?? ??, ?? ?? ?? ?.
8-54. TR1? ??? ?? ????? ????? ??? ??? ??
? C99 ??? ?? ?? : C99? ?????? C++? ?????? ?? ?
???.
? ?? ???? : ?? 47?? ??? ???? ???? ??.
? ??? ?? ??? ?? ???? ??? ???
????? ? ? ??.
? tr1::result_of : ?? ?? ??? ?? ??? ????.
??? ???????? ????? ??? ? ???
? ????? ???? ??? ?? ? ? ??.
8-55. Boo×ÓÓÐÓH! ???? ? ??? ????
???? C++????? ???? ?? C++????? ??? ????.
C++??? ????? ???? ???? ?? ?? ??? ??? ??
??? ????? ? ? ??.
?? ?? ?? ???? ?? ?? ??? ?????? ?? ???? ??
????? ???? ??, ?? ??? ?? ??? ??????
??¡¤??¡¤??? ??? ????? ???? ??.
??? ??? ??? ?????? ???? ??? ??? ??.
http://boost.org
8-55. Boo×ÓÓÐÓH! ???? ? ??? ????
? ??? ? ??? ??
? ????
? ?? ?? ? ?? ?????
? ??? ?????
? ??? ???????
? ?? ? ?? ??
? ??? ?? ???
? ????
? ? ?? ?? ??
? ???
¡­ ?? ??? ??? ????.

More Related Content

What's hot (20)

PPTX
Effective c++ Chapter1,2
?? ?
?
PPTX
More effective c++ 2
?? ?
?
PDF
Effective c++ chapter 1,2 ??
Nam Hyeonuk
?
PDF
More effective c++ ??????30????
Dong Chan Shin
?
PPTX
NHNNEXT ???14 Subway Rocket Team Study 3rd C++
Min-soo Park
?
PDF
Effective c++ chapter3, 4 ???
Dong Chan Shin
?
PPTX
Effective c++chapter3
?? ?
?
PPTX
Effective c++ 1,2
?? ?
?
PPTX
Effective c++chapter8
?? ?
?
PPTX
Effective c++chapter4
?? ?
?
PPTX
Effective c++chapter1 and2
?? ?
?
PPTX
Effective c++ ?? 1~2
Injae Lee
?
PPTX
More effective c++ 1
?? ?
?
PPTX
Effective c++ 2
?? ?
?
PPTX
Effective c++ 1
?? ?
?
PPTX
More effective c++ 3
?? ?
?
PPTX
Effective C++ Chaper 1
?? ?
?
PPTX
?? ???? c++ 1,2? ???
quxn6
?
PDF
Start IoT with JavaScript - 1.??
Park Jonggun
?
PPTX
The C++ Programming Language 5? ???, ??, ???
??
?
Effective c++ Chapter1,2
?? ?
?
More effective c++ 2
?? ?
?
Effective c++ chapter 1,2 ??
Nam Hyeonuk
?
More effective c++ ??????30????
Dong Chan Shin
?
NHNNEXT ???14 Subway Rocket Team Study 3rd C++
Min-soo Park
?
Effective c++ chapter3, 4 ???
Dong Chan Shin
?
Effective c++chapter3
?? ?
?
Effective c++ 1,2
?? ?
?
Effective c++chapter8
?? ?
?
Effective c++chapter4
?? ?
?
Effective c++chapter1 and2
?? ?
?
Effective c++ ?? 1~2
Injae Lee
?
More effective c++ 1
?? ?
?
Effective c++ 2
?? ?
?
Effective c++ 1
?? ?
?
More effective c++ 3
?? ?
?
Effective C++ Chaper 1
?? ?
?
?? ???? c++ 1,2? ???
quxn6
?
Start IoT with JavaScript - 1.??
Park Jonggun
?
The C++ Programming Language 5? ???, ??, ???
??
?

Similar to ???? C++ (7~9) (20)

PDF
EC 789
Gyeongwook Choi
?
PPTX
Effective c++ chapter 7,8
?? ?
?
PPTX
Chapter7~9 ppt
Injae Lee
?
PDF
7 8 1
nexthw
?
PDF
Effective c++ chapter7_8_9_dcshin
Dong Chan Shin
?
PPTX
???? C++ 789 ??
quxn6
?
PDF
Effective C++ Chapter 1 Summary
SeungYeonChoi10
?
PPTX
Effective c++ 1~8?
Shin heemin
?
PPTX
Effective c++ ?? chapter 4
?? ?
?
PDF
C++ Advanced ?? 5??
HyunJoon Park
?
PDF
MEC++ 1, 2
Gyeongwook Choi
?
PPTX
Effective c++(chapter 5,6)
?? ?
?
PPTX
Effective c++ ?? 2 ??
?? ?
?
PPTX
C++11
Yubin Lim
?
PPTX
More effective c++ Chap1~2
Injae Lee
?
PPTX
Effective c++ ?? chapter 8
?? ?
?
PPTX
???? 2
Young Wook Kim
?
PPTX
C++ ??? ??.pptx
sung suk seo
?
PDF
Effective c++ chapter1 2_dcshin
Dong Chan Shin
?
Effective c++ chapter 7,8
?? ?
?
Chapter7~9 ppt
Injae Lee
?
7 8 1
nexthw
?
Effective c++ chapter7_8_9_dcshin
Dong Chan Shin
?
???? C++ 789 ??
quxn6
?
Effective C++ Chapter 1 Summary
SeungYeonChoi10
?
Effective c++ 1~8?
Shin heemin
?
Effective c++ ?? chapter 4
?? ?
?
C++ Advanced ?? 5??
HyunJoon Park
?
MEC++ 1, 2
Gyeongwook Choi
?
Effective c++(chapter 5,6)
?? ?
?
Effective c++ ?? 2 ??
?? ?
?
C++11
Yubin Lim
?
More effective c++ Chap1~2
Injae Lee
?
Effective c++ ?? chapter 8
?? ?
?
C++ ??? ??.pptx
sung suk seo
?
Effective c++ chapter1 2_dcshin
Dong Chan Shin
?
Ad

???? C++ (7~9)

  • 1. 7-41. ??? ?????? ???? ??? ?????? ??? ?? ????? ? ?? ?? ??? ?? ? w? swap, normalize, !=???, > ??? ?? ????? ??? ????? ??? ???. ??? w? ?? ??? ?????? ??. ? ?? ? ??? w? ?? ??? ? ? ???? ?????? ?????, T? ?? ????? ?? ?? ??? ?????? ? ?????? ???? ??? ??? ????. ??? ??? ?? ???????.
  • 2. 7-41. ??? ?????? ???? ??? ?????? ??? ?? ????? ? ??? ?? ?? ??? ??? ??? ?? ?? ?? ??? ? ?? ?????? ??? ?????? ??. ? ?? ? ???? ??? ????? ??? ? ?? ??? ??? ???? ?? ?? ???? ?? ?? ????. ??? ??? ??? ?????? ??.
  • 3. 7-42. typename? ? ?? ??? ??? ???? ? ??? ?? ???? ????? iterator? ???? T???? ?? ???? ? ?? ??. ? ??? ????? ?? ?? ?? ??? ????. ? ?????? iterator???? ????? ???? ??? ?? typename? ????? ??. ????? template<class T>? template<typename T>? ??? ??. ?? ??? ?? ?? typename? ????.
  • 4. 7-42. typename? ? ?? ??? ??? ???? ? std::iterator_traits<T>::value_type?? T??? ??? ???? ??? ????? ????. ? ?, T??? ??? ???? ??? ?? ??? temp? ???? iter? ???? ??? temp? ??? ???. ? ???¡­ std::iterator_traits<T>::value_type ¡­? ??. ?? ? ???? ?? ??? ?? ??? ?? typedef? ??. typedef typename std::iterator_traits<T>::value_type value_type; value_type temp( *iter );
  • 5. 7-43. ????? ???? ?? ??? ?? ??? ???? ??? ?? ?? ??? ?? ???? ??? ??. 2?? ???? ??? ???? ???. ????? Derived? ???? ? Tclass? ??? ?? Base? ???? ??? ? ??? ?? ????. ????? 3??? ??.
  • 6. 7-43. ????? ???? ?? ??? ?? ??? ???? ??? ?? ?? ???? 3??? ??? ?? ? Func1() ?? this->Func1()? ????. ??? ??? Func1()? ???? ??? ?????. ? Func1()?? ?? using Base<Tclass>::Func1;? ?????? Func1()??? ??? ?????. ? Base<Tclass>::Func1();? ???? ??? ???? ?????. ?? ? ??? ???? ???? ????? ???? ???.
  • 7. 7-43. ????? ???? ?? ??? ?? ??? ???? ??? ?? ?? ¡ù?? ??? ???? ? ?? ???? ???? ??? ?? ??? ?? ??? ???? ??? ??? Func1()? ???? ???? ??? ??? ?? ??.
  • 8. 7-44. ????? ???? ??? ??????? ????? ??? ??? ??? ?? ??? ????? ? ?? ?? ?? ??, ??? ? ??? ???? ???? ??? ???. ??? ?? n??? ????? ??? ??? ???? ??? ??. ??? 5x5?? 10x10??? ??? ???? SquareMatrix???? 2?? ??? ??.
  • 9. 7-44. ????? ???? ??? ??????? ????? ? ? ????? ??? 2? ????? ??? 5, 10? ??? ?? ??? ??? ??? ??? ??? ?? ???? ??. ??? ?? n?? ???? ????? ???? ??? ?? ??? ??? ? ??.
  • 10. 7-44. ????? ???? ??? ??????? ????? ??? ? ? ???? ??? ???. invert ??? ?? ?? ??? ?? ?????? ??? ?? ??? ?? ???? ?? ??. ??? ????? ??? ?? ??????? ?????? ???? ???? ????? ??.
  • 11. 7-44. ????? ???? ??? ??????? ????? ¡ù?? ???? ??? ??? ???? ??? ??? ????? ??? ??? ??? ?? ? ? ??. ??, ???? ?? ??? ??? ???? ??? ?? ???? ???? ???? ??? ??? ????? ??? ?? ??? ??? ?? ? ???? ??? ?? ????.
  • 12. 7-45. ¡°???? ?? ??¡±? ????? ?? ?? ?? ???? ??! ?? ?? ???? ???? ??, ?????? ???? ?????? ???? ??? ??? ????. ?? ?? ???? ?????? ??? ???? ????. ??? ?? ???? ?? ? ??? ??? ??? ???? ????? ??? ??? ??? ?????. ?? ?? ??? ???? ???? ??.
  • 13. 7-45. ¡°???? ?? ??¡±? ????? ?? ?? ?? ???? ??! ??? ?? ?? ??? ???? ?? ?? ?? ???? ??? ??? ??? U?? ???? T?? ???? ??? ?? ??? ??? ? ?? ?? ? ??. ???? ??? ?? ???? ?? ?? ???? ??? ??? ? ??? ?????.
  • 14. 7-46. ?? ??? ???? ???? ??? ??? ??? ??? ?? ??? ?? ??? ??? ??? ? ??? ????? ?? ???? 24???? ?? ????? ?? ??? ???? ??? ????. Rational<int> oneHalf( 1, 2 ); Rational<int> result = oneHalf * 2; ??? ?? ???? 2?? ?? 2? ?? ??? ?? ?? ??? ??.
  • 15. 7-46. ?? ??? ???? ???? ??? ??? ??? ??? ?? ??? ?? ?? ?? ??? ?? friend? ????? ????? ?? ???? ??. ??? ???? ?? ?? ??? ?? ?? ??? ?? ??? ??. ??? ??? ?? ?? ??? ??? inline????? ?? ?? ?? ??? ??? ???? ??? ???? ???? ??.
  • 16. 7-47. ??? ?? ??? ????? ???? ???? ???? ???? ??? ???? ?? ??? ??? ????? ??. ?? ???? 5?? ??? ??, ?? ???? ?? ?? ???? ??. input_iterator_tag : ?? ???. ????? 1? ?? ? ??? ????. output_iterator_tag : ?? ???. ????? 1? ?? ? ??? ????. forward_iterator_tag : ??? ???. ?? ???? ????. ??? ???? ?? ? ????. bidirectinal_iterator_tag : ??? ???. ??? ???? ????. ??? ???? ?? ? ????. random_access_iterator_tag : ?? ?? ???. ??? ???? ????. ????? ??? ?? ??, ???? ?? ? ????.
  • 17. 7-47. ??? ?? ??? ????? ???? ???? ???? ??? ??? ??? ?? ??? ?? ?? iterator_traits ?? ??? ???? ?? ? ??. ??? ?? ??? ???? ???? ?? ???? ???? ?? ?? ???? ???. ??? ????? typedef? ??? ??? ?? iterator_category? ????. (vector??? ?? ?? ?????.)
  • 18. 7-47. ??? ?? ??? ????? ???? ???? ???? Iterator_traits??? ?? ??? ??? ??? iterator_category? ??? ????. ?? ??? ???? ???? ??? ??? ?? ?? ???? ???? ??? ?? ???? ???.
  • 19. 7-47. ??? ?? ??? ????? ???? ???? ???? ?? ?? ??? ??? ???. ?? ???? ??? ??? ?? ???. ??? ? ??? ???? ??? ???? ?? ?, ??? ?? ??? ??? ??? ??.
  • 20. 7-47. ??? ?? ??? ????? ???? ???? ???? C++?? TR1?? ?? ?? ?? ?? ???? 50? ???. ( ex> is_array<T>, is_base_of<T1, T2>, ?? ) ??? ?? ??? ??? ??? ??? ?? ???? ??? ?? ?? ?? ?? ???? ?? ?? ??? ?? ???? ?????? ? ???? ??? ??? ???? ? ??.
  • 21. 7-48. ??? ???????, ?? ????? ??? ?? ?????(TMP)? ??? ????? ?? ??? ??? ???? ??? ? ??? ?? ??? ??. ??? ?? ?? ?? ????? ?? ? ??? ??? ???? ???? ?? ????, ????? ?? ? ??? ??? ???? ??? ??? ???? ??????? ??? ??? ??? ????? ?? ????. (¡ù?? ?? ?? ??? ??? ???? ??.)
  • 22. 7-48. ??? ???????, ?? ????? ?? ?? ???? ?? ???? ?? ? TMP? ???? ??? ??. ?? ?? ??? ??? ???? ?? ?? ??? ?? ?? ?? ??? ???? ??.
  • 23. 7-48. ??? ???????, ?? ????? TMP? ??? ?? ??? ??? ? ??. ? ??(??, ??, ?? ?)? ??? ?? ?? ?? ??? ??????? ??? ?? ??? ??? ??? ??. TMP? ?? ??? ???? ???? ? ??. ? ?? ??? ??? ? ??? ??? ?? ??? ?? typedef SquareMatrix<double, 10000> BigMatrix; BigMatrix m1, m2, m3, m4, m5; ... BigMatrix result = m1 * m2 * m3 * m4 * m5; ??? ??? ????? ??? ?? ?? ???? ?? ??? ???? ???? ??? ??? ? ? ??.
  • 24. 8-49. new ???? ?? ??? ??? ???? new???? ??? ??? ???? ? ??? ??? ?? ???? ??? new_handler?? ??, ?? ???? ??(??) ????. set_new_handler??? ???? ? ??? ??? new_handler? ???? ?? ??? ?? ?? new_handler? ????. new_handler?? ??? ?? ??? ?? ? ??. ? ??? ? ?? ???? ? ????. ? ??? ??? ? ?? ?? new ???? ????. ? ??? new ???? ???? ??? ??? ??. ? bad_alloc?? ??? ??? ??? ??? ??? ?? ??? ????. ? ???? ?? ??? abort? exit ?? ????.
  • 25. 8-49. new ???? ?? ??? ??? ???? ?? ?? ???? ??? ????? ?? ??? ? set_new_handler? ??? ? ??. ??? ??? ??? ????? ?? ???? ??? ???? ??? CRTP?? ??. ¡ù CRTP : Curiously Recurring Template Pattern
  • 26. 8-49. new ???? ?? ??? ??? ???? 1993???? new? ??? ??? ?? ? null???? ?? ??? ? ? ? ??? bad_alloc ??? ???? ???. ??? ?? null??? ??? ???? ??? ????? ???? ? ??? ?? ??? ??? ??. ??? null???? ???? ? ??? ¡°????(nothrow)¡± ???? ??. class Widget { ... }; Widget *pw = new ( std::nothrow ) Widget; if( pw == nullptr ){ ... } ??? ??? ????. ?? ??? ???? ??? ????? ?? ?? ?? ?? ?? new?? ??? ??? ???.
  • 27. 8-50. new ? delete? ?? ??? ?? ??? ???? ??? ?? operator new? operator delete? ???? ??? ?? 3??? ???. ? ??? ? ??? ????. - new? ??? ??? ??? ?? ? delete? ??? ????? delete? ????? ?? delete ?? ??? ?? ? ??. - ?? ??? ??? ?? ???/??? ??? ??? ?? ????? ? ? ? ??. ? ??? ?????. - ?? ???? new? ??? ????? ????? ????? ???. ???? ???? ????? ??? ??? ??. ? ?? ?? ???? ?? ?? ??? ????.
  • 28. 8-50. new ? delete? ?? ??? ?? ??? ???? ??? ?? ??? ??? ?? ????? ???. ? ?? ??? ???? ?? ????? ???. ? ??? ??? ?? ???? ??? ?? ??? ????. - ?? ?? ????? double ?? ?? ? 8??? ??? ???? ?? ??? ??. ?? ?? new? ???? ?? ??? ?? ? ??. ? ??? ??? ?? ?? ???? ? ?? ?????. - ?? ?? ??? ?? ?????? ??? ?? ?? new/delete? ???? ?? page? ?? page fault? ??? ? ? ??. ? ???? ??? ??? ????? ??. - ?? new/delete? ???? ?? ??? ???? ?? ?? ¡ù ???? ??, ???? ??? ?? ????? ???? ?? ????? ????.
  • 29. 8-51. new ? delete? ??? ? ??? ? ??? ??? ? ?? ?? new ? ?? ?? ??? ?? ?? ? - ?? ?? ?? ???? ???? ?. - ?? ??? ??? new ???? ?? ?? ??? ??? ?????. - new? new ??? ???? null? ???? bad_alloc??? ???. ? ?? ???? ???? new ??? ??? ??? ? ? ??? ??(0 byte) ??? ??? ???? ?? ? ? ?? ??? new? ???? ??? ? ? ? ?? ???? ?? ?? ???? new? ???? ??? ??? ??? ? ???? ???? ????. - ?? ??? ???? ??? ??? ??? ?? ???? new? ??.
  • 30. 8-51. new ? delete? ??? ? ??? ? ??? ??? ? ?? ?? delete ? null???? ?? delete? ??? ????. ? ??? ???? ??? ?????. - ?? ?? ??? ???? ??? ??? ?? ?? ?? delete? ??.
  • 31. 8-52. ???? new? ????? ???? delete? ?? ???? ?? ?? ???? ??? ?? new? ???? ???? ????? Widget ????? ??? ??? ?? C++??? ????? delete? ???? ??. ?? ??? ???? ?? new? ?? ?? delete? ???? ???? ???? ?? ??? ??? ????. ??? ??? ????? ???? ? ? delete ??? ??? ??? delete? ????. ?, ???? new? ?? ??? ??? delete? ???? delete? ?? ??? ??? ??. Widget *pw = new (std::cerr) Widget;
  • 32. 8-53. ???? ??? ???? ?? ??(warning) ???? ????? ? ??. ????? ??? ???? ??? ? ???? ?? ??. ?? ??? ?? Warning: Derived::Func() hides virtual Base::Func() ?? ??? ??. ?? ??? ??? ????? ??? const? ????? ????? ??? ????? ???? ?? ???. ¡ù?? ?? ???? ????? ?? ??????. ???? ????? ???.
  • 33. 8-54. TR1? ??? ?? ????? ????? ??? ??? ?? C++98? ?? C++?????? ?? ?? ??? ??? ??. ? ?? ??? ?????(STL: Standard Template Library) ? iostream : ??? ?? ???, ??? ?? ???, cin, cout, cerr ?. ? ??? ?? : ?? ???(locale)? ????(wchar_t, wstring) ??. ? ?? ?? ??: ??? ???(complex), ???? ???(valarray)?. ? ?? ??? : exception ? logic_error, runtime_error ?. ? C89? ?? ????? ?? ???? ?? ???? ??.
  • 34. 8-54. TR1? ??? ?? ????? ????? ??? ??? ?? TR1? ???. ? ??? ??? : shared_ptr? ?? ??? ??? ?? ???? 0? ?? ? ??. weak_ptr? ?? ??? ?????. ? tr1::function : ?? ??? ????? ???? ????? ?? ???? ??? ????. ?? ???? ????? ¡°int? ?? string? ???? ??¡±?? ????. ? tr1::bind : STL? bind1st, bind2nd? ?? ??? ?? ?? ?? ??? ????. ??? ??? ??? ?? ?? ??????, ?? ?? ??? ?? ???? ?? ? ??. void regCallBack( std::string func( int ) ); void regCallBack( std::string ( int ) );
  • 35. 8-54. TR1? ??? ?? ????? ????? ??? ??? ?? ? ?? ??? : ?? ???? ???? ??, ?, ????? ?????. tr1::unordered_set, tr1::unordered_multiset, tr1::unordered_map, tr1::unordered_multimap. ? ?? ??? : ?? ??? ??? ??, ?? ???? ?????. ? ?? : pair? ????? 2??? ? ??? ?? ? ??. ? tr1::array : ¡°STL??? ?¡± ??. ? tr1::mem_fn : ?? ?? ???? adapt??? ??. mem_fun, mem_fun_ref ?? ???. ? tr1::reference_wrapper : ??? ???? ???? ?? ? ?? ???. ? ?? ?? : ?? rand? ???. ? ?? ??? ?? ?? : ??? ???, ?? ??, ?? ?? ?? ?.
  • 36. 8-54. TR1? ??? ?? ????? ????? ??? ??? ?? ? C99 ??? ?? ?? : C99? ?????? C++? ?????? ?? ? ???. ? ?? ???? : ?? 47?? ??? ???? ???? ??. ? ??? ?? ??? ?? ???? ??? ??? ????? ? ? ??. ? tr1::result_of : ?? ?? ??? ?? ??? ????. ??? ???????? ????? ??? ? ??? ? ????? ???? ??? ?? ? ? ??.
  • 37. 8-55. Boo×ÓÓÐÓH! ???? ? ??? ???? ???? C++????? ???? ?? C++????? ??? ????. C++??? ????? ???? ???? ?? ?? ??? ??? ?? ??? ????? ? ? ??. ?? ?? ?? ???? ?? ?? ??? ?????? ?? ???? ?? ????? ???? ??, ?? ??? ?? ??? ?????? ??¡¤??¡¤??? ??? ????? ???? ??. ??? ??? ??? ?????? ???? ??? ??? ??. http://boost.org
  • 38. 8-55. Boo×ÓÓÐÓH! ???? ? ??? ???? ? ??? ? ??? ?? ? ???? ? ?? ?? ? ?? ????? ? ??? ????? ? ??? ??????? ? ?? ? ?? ?? ? ??? ?? ??? ? ???? ? ? ?? ?? ?? ? ??? ¡­ ?? ??? ??? ????.