More Related Content
What's hot (20)
PPTX
Effective c++ Chapter1,2?? ??
PPTX
More effective c++ 2?? ??
PPTX
NHNNEXT ???14 Subway Rocket Team Study 3rd C++Min-soo Park?
PPTX
Effective c++chapter3?? ??
PPTX
Effective c++ 1,2?? ??
PPTX
Effective c++chapter8?? ??
PPTX
Effective c++chapter4?? ??
PPTX
Effective c++chapter1 and2?? ??
PPTX
More effective c++ 1?? ??
PPTX
More effective c++ 3?? ??
PPTX
Effective C++ Chaper 1?? ??
PPTX
?? ???? c++ 1,2? ???quxn6?
PPTX
The C++ Programming Language 5? ???, ??, ????? ?
Similar to ???? C++ (7~9) (20)
PPTX
Effective c++ chapter 7,8?? ??
PPTX
???? C++ 789 ??quxn6?
PPTX
Effective c++ ?? chapter 4?? ??
PPTX
Effective c++(chapter 5,6)?? ??
PPTX
Effective c++ ?? 2 ???? ??
PPTX
Effective c++ ?? chapter 8?? ??
???? 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! ???? ? ??? ????
? ??? ? ??? ??
? ????
? ?? ?? ? ?? ?????
? ??? ?????
? ??? ???????
? ?? ? ?? ??
? ??? ?? ???
? ????
? ? ?? ?? ??
? ???
¡ ?? ??? ??? ????.