new delete new delete string string Array new

  • Slides: 8
Download presentation
new, delete, new[] , delete[] string* string. Array = new string[100]; delete string. Array;

new, delete, new[] , delete[] string* string. Array = new string[100]; delete string. Array; // 소멸자 호출 수에 문제 typedef string Address. Lines[4]; string* pal = new Address. Lines; delete pal; delete[] pal; // ? ?

스마트 포인터에 저장하는 코드는 명확히 void process. Widget(shared_ptr<Widget> pw, int priority); // 선언 process.

스마트 포인터에 저장하는 코드는 명확히 void process. Widget(shared_ptr<Widget> pw, int priority); // 선언 process. Widget(new Widget, priority()); // process. Widget(shared_ptr<Widget>(new Widget), priority()); shared_ptr<Widget> pw(new Widget); process. Widget(pw, priority()); //

값에 의한 참조보다는 상수 객체에 의한 전달 bool validate. Student(Student s); bool validate. Student(const

값에 의한 참조보다는 상수 객체에 의한 전달 bool validate. Student(Student s); bool validate. Student(const Student& s);

함수에서 객체를 반환해야 할 경우 inline const Rational operator*(const Rational& lhs, const Rational& rhs)

함수에서 객체를 반환해야 할 경우 inline const Rational operator*(const Rational& lhs, const Rational& rhs) { return Rational(lhs. n * rhs. n, lhs. d * rhs. d); }

멤버 함수보다는 비멤버 비프렌드 함수와 더 가까워지자 void Web. Browser: : clear. Everything() {

멤버 함수보다는 비멤버 비프렌드 함수와 더 가까워지자 void Web. Browser: : clear. Everything() { clear. Cache(); clear. History(); remove. Cookies(); } void clear. Everything(Web. Browser& wb) { wb. clear. Cache(); wb. clear. History(); wb. remove. Cookies(); } 비멤버 비 프렌드 함수는 어떤 클래스의 private 멤버 부분을 접근할 수 있는 함수의 개수를 늘리지 않는다.

타입 변환이 모든 매개변수에 대해 적용되어야 한다면 비멤버 함수를 선언하자. class Rational { public:

타입 변환이 모든 매개변수에 대해 적용되어야 한다면 비멤버 함수를 선언하자. class Rational { public: Rational(int numerator = 0, int denominator = 1); // explicit 사용 X const Rational operator* (const Rational& rhs) const; }; result = one. Half * 2; result = 2 * one. Half; // // const Rational operator* (const Rational& lhs, const Rational& rhs) { return Rational(lhs. numerator() * rhs. numerator(), lhs. denominator() * rhs. denominator()); }