This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <vector> | |
| #include <string> | |
| #include <thread> | |
| #include <mutex> | |
| using namespace std; | |
| namespace Item29 { | |
| //예외 안전성이 확보되 그날 위해 싸우고 또 싸우자 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <vector> | |
| #include <string> | |
| using namespace std; | |
| namespace Item28 { | |
| //내부에서 사용하는 객체에 대한 '핸들'을 반환하는 코드는 되도록 피하자 | |
| class Point { | |
| public: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <vector> | |
| #include <string> | |
| using namespace std; | |
| namespace Item27 { | |
| //캐스팅은 절약, 또 절약! 잊지 말자 | |
| void Func2() { | |
| int x = 1, y = 5; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <vector> | |
| #include <string> | |
| using namespace std; | |
| namespace Item26 { | |
| //변수 정의는 늦출 수 있는 데까지 늦추는 근성을 발휘하자 | |
| //예시 1 - 비밀번호가 충분히 길 때 해당 비밀번호를 암호화하는 함수 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <vector> | |
| #include <string> | |
| using namespace std; | |
| namespace Item25 { | |
| //예외를 던지지 않는 swap에 대한 지원도 생각해 보자 | |
| //Effective C++ 은 무브 시맨틱(move semantic) 이 C++에 소개되기 이전에 나온 책인것을 고려할 것 | |
| //현재 표준 swap은 이동 생성/대입을 활용하기 때문에 복사 생성/대입을 활용하는 예전 swap과는 다름 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <vector> | |
| #include <string> | |
| using namespace std; | |
| namespace Item24 { | |
| //타입 변환이 '모든 매개변수'에 대해 적용되어야 한다면 비멤버 함수를 선언하자 | |
| class Rational { //곱셈 연산을 지원하는 유리수 클래스 | |
| public: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <vector> | |
| #include <string> | |
| using namespace std; | |
| namespace Item23 { | |
| //멤버 함수보다는 비멤버 비프렌드 함수와 더 가까워지자 | |
| class WebBrowser { //웹 브라우저를 나타내는 클래스가 하나 있다고 가정 | |
| public: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //함수에서 객체를 반환해야 할 경우에 참조자를 반환하려고 들지 말자 | |
| class Rational { | |
| public: | |
| Rational(int numerator = 0, int denominator = 1) : n(numerator), d(denominator) {} | |
| private: | |
| int n, d; | |
| friend const Rational operator* (const Rational& rhs, const Rational& lhs); | |
| //const 객체를 반환하는 이유는 a * b = c 같은 경우를 방지하기 위함. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //'값에 의한 전달' 보다는 '상수객체 참조자에 의한 전달' 방식을 택하는 편이 대개 낫다 | |
| class Person { | |
| public: | |
| string name; | |
| string address; | |
| }; | |
| class Student : public Person { | |
| public: | |
| string schoolName; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <vector> | |
| #include <string> | |
| using namespace std; | |
| namespace Item18 { | |
| //인터페이스 설계는 제대로 쓰기엔 쉽게, 엉터리로 쓰기엔 어렵게 하자 | |
| //예시 1 : 날짜 | |
| struct Day { |