1. 11-1 상속의 기본 is-a relation ship [1/2] - class Child : public Mother // derived class : generalized class - 같은 이름의 메서드 사용시 child class의 것을 우선사용 - mother class 의 프라이빗 멤버에 child 는 접근 불가 - protected: private 상태는 유지하면서 자식에게는 접근 허용 - constructor 는 메모리가 할당 될때 initialize를 요청 - child class 가 생성될 때 mother class의 생성자를 같이 호출
1. 9-5 증감 연산자 오버로딩하기// prefixDigit& operator ++(){++m_digit;return *this;} //postfixDigit operator ++(int){Digit temp(m_digit);++(*this);return temp;}- postfix 오버로딩의 경우 더미 argument를 삽입해줘야한다.- postfix 부분의 return 타입을 Digit&으로 바꿨더니warning: reference to local variable ‘temp’ returned [-Wreturn-local-addr] 라는 경고문이 뜨고 실행하면 Segmentation fault(core dumped)가 뜬다. 이유는 temp의 레퍼런스를 반환하게하고 싶은데 후순위 ++ 연산자가 작동을..
따라배우는 C++ (홍정모)https://www.youtube.com/watch?v=KJGxrd2Ac24&list=PLNfg4W25Tapw5Yx4yuExHNybBIUk68aNz 1. 9-1 산술연산자 오버로딩(overloading) 하기-const를 뒤에 붙이면 같은 이름도 오버로딩 된다는 것을 까먹어서 조금 헤멤- 핵신기,, c++로 파이썬 만들수도 있을듯Cents operator + (const Cents &c1, const Cents &c2){return Cents(c1.getCents() + c2.getCents());}cout 연산자 말고 < 연산자를 오버로딩 해야함 (인터레스팅..)
1. 8-12 친구 함수와 클래스 friend- 연산자 오버로딩에서 가장 많이 사용함- 전방 선언(foward declaration) class B;class A 내부에서 class B에관한 내용이 있는데 B가 늦게 선언되어 있으면 A앞에 전방선언을 해준다.2. 8-13 익명개체 (anonymous)- lvalue, rvalue?== lvalue : 단일 식을 넘어 지속되는 개체를 참조. 모든변수 rvalue : rvalue를 사용하는 식 외에서는 유지되지 않는 임시 값. https://msdn.microsoft.com/ko-kr/library/f90831hc.aspx- class A 의 메서드 print()가 있다고 했을 때 A(1).print()처럼 바로 사용가능. 이때 A는 rvalue와 비슷== ..
1.8-8 클래스와 헤더파일-inline 함수?-여러파일 함께 컴파일 g++ 8-8.cc Calc.cc 2. 8-9 클래스와 const- const로 인스턴스 생성시 member function이 const라고 생성해줘야 쓸 수 있음.ex) int getValue() const- const 적극 활용 권장- defualt copy constructorSomething(const Something* st_in){m_value = st_in.m_value;}- 클래스를 argument로 보낼때는 const Something &st 형태로 보내면 좋다.- const가 있냐없냐로 오버로딩도 가능3. 8-10 정적 멤버 변수- const 가 아닌 static 멤버 변수는 initialize가 불가능 하다.- st..