SlideShare a Scribd company logo
1 of 32
C++ 수행평가
2317 이재희
목차
Chapter 11. 클래스의 활용
• 연산자 오버로딩
• 프렌드
• 자동 변환과 클래스의 데이터형 변환
Chapter 12. 클래스와 동적 메모리의 대입
• 동적 메모리와 클래스
• 생성자에 new를 사용시 주의할 점
• 객체 리턴에 대한 관찰
연산자 오버로딩
Chapter11. 클래스의 활용
연산자 오버로딩
연산자 오버로딩이란?
 객체 연산을 편리하게 해주는 기술
 C++의 다형(Polymorphism)의 한 예
 함수 오버로딩과 비슷하다
연산자 오버로딩
연산자 오버로딩
연산자 오버로딩
return operatorOP (argument-list)
연산자 오버로딩
연산자 오버로딩 제약
 오버로딩된 연산자는 최소 하나의 피연산자가 사용자 정의 데이터형
이여야 한다.
연산자 오버로딩
 오버로딩된 연산자는 원래의 연산자에 적용되는 문법을 위반 할 수 없
다.
 연산자 기호를 새로 만들 수 없다.
연산자 오버로딩
연산자 설명
sizeof sizeof 연산자
. 멤버 연산자
.* 멤버 지시 포인터 연산자
:: 사용 범위 결정 연산자
?: 조건 연산자
typeid RTTI 연산자
const_cast 데이터 형 변환 연산자
dynamic_cast 데이터 형 변환 연산자
reinterpert_cast 데이터 형 변환 연산자
static_cast 데이터 형 변환 연산자
 아래의 연산자는 오버로딩 할 수 없다.
연산자 오버로딩
연산자 설명
= 대입 연산자
() 함수 호출 연산자
[] 배열 인덱스 연산자
-> 클래스 멤버 접근 포인터 연산자
 아래의 연산자는 멤버 함수로만 오버로딩 할 수 있다.
프렌드
Chapter11. 클래스의 활용
프렌드
프렌드란?
 객체의 private 멤버에 접근 할 수 있는 또 다른 방법
 해당 클래스의 멤버 함수와 동등한 접근 권한을 가짐
프렌드
자동 변환과 클래스의 데이터 형 변환
Chapter11. 클래스의 활용
자동 변환과 클래스의 데이터 형 변환
자동 변환과 클래스의 데이터 형 변환
자동 변환과 클래스의 데이터 형 변환
자동 변환과 클래스의 데이터 형 변환
operator typename ()
 변환 함수는 클래스의 함수여야 한다.
 변환 함수는 리턴형을 가질 수 없다.
 변환 함수는 매개변수를 가질 수 없다.
동적 메모리와 클래스
Chapter12. 클래스와 동적 메모리 대입
동적 메모리와 클래스
동적 메모리란?
 프로그램 실행중에 생성되는 메모리
 new 키워드를 이용해 메모리 생성
 delete 키워드를 이용해 메모리 해제
동적 메모리와 클래스
특별 멤버 함수
 생성자를 정의하지 않았을 경우 디폴트 생성자
 파괴자를 정의하지 않았을 경우 디폴트 파괴자
 복사 생성자를 정의하지 않았을 경우 디폴트 복사 생성자
 대입 연산자를 정의하지 않았을 경우 디폴트 대입 연산자
 주소 연산자를 정의하지 않았을 경우 디폴트 주소 연산자.
동적 메모리와 클래스
복사 생성자와 대입 연산자의 차이점
동적 메모리와 클래스
디폴트 복사 생성자와 디폴트 복사 대입 연산자의 문제점
동적 메모리와 클래스
동적 메모리와 클래스
StringBad 객체
임시 StringBad 객체
ShowStringBad2
“Hello1”
호출
“Hello1”
생성자에 new를 사용시 주의할 사항
Chapter12. 클래스와 동적 메모리 대입
생성자에 new를 사용시 주의할 사항
 생성자에서 new를 이용하여 포인터 멤버를 초기화 했다면, 파괴자에서
반드시 delete를 사용해야 한다.
 new와 delete의 사용은 서로 어울려야 한다. new는 delete와 짝을 이루
고 new[]는 delete[]와 짝을 이루어야 한다.
 대입 연산자를 정의하지 않았을 경우 디폴트 대입 연산자
 파괴자는 하나밖에 없으므로, 모든 생성자가 그 파괴자와 어울려야 한
다.
객체 리턴에 대한 관찰
Chapter12. 클래스와 동적 메모리 대입
객체 리턴에 대한 관찰
객체에 대한 참조 리턴
 참조 객체를 리턴함으로써 복사 생성자가 호출되지 않는다.
객체 리턴에 대한 관찰
객체에 대한 참조를 리턴할때 주의할 점
 지역 객체를 리턴하면, 함수 호출이 종료될때 해당 객체는 폐
기되므로 참조가 아닌 객체를 리턴해야 한다.
객체 리턴에 대한 관찰
const 객체 리턴
v1 v2 v3
v3
v1 + v2
임시 객체

More Related Content

What's hot

Effective C++ Chaper 1
Effective C++ Chaper 1Effective C++ Chaper 1
Effective C++ Chaper 1연우 김
 
OOP 설계 원칙 S.O.L.I.D.
OOP 설계 원칙 S.O.L.I.D.OOP 설계 원칙 S.O.L.I.D.
OOP 설계 원칙 S.O.L.I.D.Ryan Park
 
자바와 사용하기2
자바와 사용하기2자바와 사용하기2
자바와 사용하기2destinycs
 
More effective c++ 1
More effective c++ 1More effective c++ 1
More effective c++ 1현찬 양
 
Effective c++ 1,2
Effective c++ 1,2Effective c++ 1,2
Effective c++ 1,2세빈 정
 
Effective c++ 1
Effective c++ 1Effective c++ 1
Effective c++ 1현찬 양
 
[ES6] 11. Modularization, import와 export
[ES6] 11. Modularization, import와 export[ES6] 11. Modularization, import와 export
[ES6] 11. Modularization, import와 exportHan JaeYeab
 
Oop design principle SOLID
Oop design principle SOLIDOop design principle SOLID
Oop design principle SOLIDRyan Park
 
Effective c++ 2
Effective c++ 2Effective c++ 2
Effective c++ 2현찬 양
 
More effective c++ 2
More effective c++ 2More effective c++ 2
More effective c++ 2현찬 양
 
Effective c++ chapter 1,2 요약
Effective c++ chapter 1,2 요약Effective c++ chapter 1,2 요약
Effective c++ chapter 1,2 요약Nam Hyeonuk
 
Effective c++ 정리 1~2
Effective c++ 정리 1~2Effective c++ 정리 1~2
Effective c++ 정리 1~2Injae Lee
 
[IT기술칼럼#1]고급자바스크립트 for AngularJS, React_고급자바스크립트,AngularJS,React전문교육학원
[IT기술칼럼#1]고급자바스크립트  for AngularJS, React_고급자바스크립트,AngularJS,React전문교육학원[IT기술칼럼#1]고급자바스크립트  for AngularJS, React_고급자바스크립트,AngularJS,React전문교육학원
[IT기술칼럼#1]고급자바스크립트 for AngularJS, React_고급자바스크립트,AngularJS,React전문교육학원탑크리에듀(구로디지털단지역3번출구 2분거리)
 
More effective c++ 3
More effective c++ 3More effective c++ 3
More effective c++ 3현찬 양
 
Effective c++ 챕터 2 정리
Effective c++ 챕터 2 정리Effective c++ 챕터 2 정리
Effective c++ 챕터 2 정리연우 김
 
이펙티브 C++ 공부
이펙티브 C++ 공부이펙티브 C++ 공부
이펙티브 C++ 공부quxn6
 
자바스터디 3 2
자바스터디 3 2자바스터디 3 2
자바스터디 3 2jangpd007
 

What's hot (20)

Effective C++ Chaper 1
Effective C++ Chaper 1Effective C++ Chaper 1
Effective C++ Chaper 1
 
OOP 설계 원칙 S.O.L.I.D.
OOP 설계 원칙 S.O.L.I.D.OOP 설계 원칙 S.O.L.I.D.
OOP 설계 원칙 S.O.L.I.D.
 
자바와 사용하기2
자바와 사용하기2자바와 사용하기2
자바와 사용하기2
 
More effective c++ 1
More effective c++ 1More effective c++ 1
More effective c++ 1
 
Effective c++ 1,2
Effective c++ 1,2Effective c++ 1,2
Effective c++ 1,2
 
Effective c++ 1
Effective c++ 1Effective c++ 1
Effective c++ 1
 
[ES6] 11. Modularization, import와 export
[ES6] 11. Modularization, import와 export[ES6] 11. Modularization, import와 export
[ES6] 11. Modularization, import와 export
 
Oop design principle SOLID
Oop design principle SOLIDOop design principle SOLID
Oop design principle SOLID
 
Effective c++ 2
Effective c++ 2Effective c++ 2
Effective c++ 2
 
15 swift 클래스
15 swift 클래스15 swift 클래스
15 swift 클래스
 
More effective c++ 2
More effective c++ 2More effective c++ 2
More effective c++ 2
 
Effective c++ chapter 1,2 요약
Effective c++ chapter 1,2 요약Effective c++ chapter 1,2 요약
Effective c++ chapter 1,2 요약
 
17 swift 프로토콜
17 swift 프로토콜17 swift 프로토콜
17 swift 프로토콜
 
Effective c++ 정리 1~2
Effective c++ 정리 1~2Effective c++ 정리 1~2
Effective c++ 정리 1~2
 
[IT기술칼럼#1]고급자바스크립트 for AngularJS, React_고급자바스크립트,AngularJS,React전문교육학원
[IT기술칼럼#1]고급자바스크립트  for AngularJS, React_고급자바스크립트,AngularJS,React전문교육학원[IT기술칼럼#1]고급자바스크립트  for AngularJS, React_고급자바스크립트,AngularJS,React전문교육학원
[IT기술칼럼#1]고급자바스크립트 for AngularJS, React_고급자바스크립트,AngularJS,React전문교육학원
 
More effective c++ 3
More effective c++ 3More effective c++ 3
More effective c++ 3
 
ES6-01
ES6-01ES6-01
ES6-01
 
Effective c++ 챕터 2 정리
Effective c++ 챕터 2 정리Effective c++ 챕터 2 정리
Effective c++ 챕터 2 정리
 
이펙티브 C++ 공부
이펙티브 C++ 공부이펙티브 C++ 공부
이펙티브 C++ 공부
 
자바스터디 3 2
자바스터디 3 2자바스터디 3 2
자바스터디 3 2
 

Similar to C++ 2학기 수행평가

Effective c++ Chapter1,2
Effective c++ Chapter1,2Effective c++ Chapter1,2
Effective c++ Chapter1,2문익 장
 
Chapter5 ~ 6
Chapter5 ~ 6Chapter5 ~ 6
Chapter5 ~ 6Injae Lee
 
Chapter7~9 ppt
Chapter7~9 pptChapter7~9 ppt
Chapter7~9 pptInjae Lee
 
The c++ programming language 10장 클래스 발표
The c++ programming language 10장 클래스 발표The c++ programming language 10장 클래스 발표
The c++ programming language 10장 클래스 발표재정 이
 
Effective c++chapter4
Effective c++chapter4Effective c++chapter4
Effective c++chapter4성연 김
 
Effective c++ chapter 7,8
Effective c++ chapter 7,8Effective c++ chapter 7,8
Effective c++ chapter 7,8문익 장
 
Effective c++chapter1 and2
Effective c++chapter1 and2Effective c++chapter1 and2
Effective c++chapter1 and2성연 김
 
Effective c++ 1~8장
Effective c++ 1~8장 Effective c++ 1~8장
Effective c++ 1~8장 Shin heemin
 
이펙티브 C++ 스터디
이펙티브 C++ 스터디이펙티브 C++ 스터디
이펙티브 C++ 스터디quxn6
 
Mec++ chapter3,4
Mec++ chapter3,4Mec++ chapter3,4
Mec++ chapter3,4문익 장
 
이펙티브 C++ (7~9)
이펙티브 C++ (7~9)이펙티브 C++ (7~9)
이펙티브 C++ (7~9)익성 조
 
Effective java
Effective javaEffective java
Effective javaHaeil Yi
 
Effective c++ chapter7_8_9_dcshin
Effective c++ chapter7_8_9_dcshinEffective c++ chapter7_8_9_dcshin
Effective c++ chapter7_8_9_dcshinDong Chan Shin
 
Effective c++ 3
Effective c++ 3Effective c++ 3
Effective c++ 3현찬 양
 
More Effective C++ 4주차
More Effective C++ 4주차More Effective C++ 4주차
More Effective C++ 4주차Injae Lee
 
이펙티브 C++ 5,6 장 스터디
이펙티브 C++ 5,6 장 스터디이펙티브 C++ 5,6 장 스터디
이펙티브 C++ 5,6 장 스터디quxn6
 
[HaU] 신입 기술 면접 준비 java
[HaU] 신입 기술 면접 준비 java[HaU] 신입 기술 면접 준비 java
[HaU] 신입 기술 면접 준비 java유리 하
 
Working Effectively With Legacy Code - xp2005
Working Effectively With Legacy Code - xp2005Working Effectively With Legacy Code - xp2005
Working Effectively With Legacy Code - xp2005Ryan Park
 
카사 공개세미나1회 W.E.L.C.
카사 공개세미나1회  W.E.L.C.카사 공개세미나1회  W.E.L.C.
카사 공개세미나1회 W.E.L.C.Ryan Park
 

Similar to C++ 2학기 수행평가 (20)

Effective c++ Chapter1,2
Effective c++ Chapter1,2Effective c++ Chapter1,2
Effective c++ Chapter1,2
 
Chapter5 ~ 6
Chapter5 ~ 6Chapter5 ~ 6
Chapter5 ~ 6
 
Chapter7~9 ppt
Chapter7~9 pptChapter7~9 ppt
Chapter7~9 ppt
 
The c++ programming language 10장 클래스 발표
The c++ programming language 10장 클래스 발표The c++ programming language 10장 클래스 발표
The c++ programming language 10장 클래스 발표
 
Effective c++chapter4
Effective c++chapter4Effective c++chapter4
Effective c++chapter4
 
Effective c++ chapter 7,8
Effective c++ chapter 7,8Effective c++ chapter 7,8
Effective c++ chapter 7,8
 
Effective c++chapter1 and2
Effective c++chapter1 and2Effective c++chapter1 and2
Effective c++chapter1 and2
 
EC 789
EC 789EC 789
EC 789
 
Effective c++ 1~8장
Effective c++ 1~8장 Effective c++ 1~8장
Effective c++ 1~8장
 
이펙티브 C++ 스터디
이펙티브 C++ 스터디이펙티브 C++ 스터디
이펙티브 C++ 스터디
 
Mec++ chapter3,4
Mec++ chapter3,4Mec++ chapter3,4
Mec++ chapter3,4
 
이펙티브 C++ (7~9)
이펙티브 C++ (7~9)이펙티브 C++ (7~9)
이펙티브 C++ (7~9)
 
Effective java
Effective javaEffective java
Effective java
 
Effective c++ chapter7_8_9_dcshin
Effective c++ chapter7_8_9_dcshinEffective c++ chapter7_8_9_dcshin
Effective c++ chapter7_8_9_dcshin
 
Effective c++ 3
Effective c++ 3Effective c++ 3
Effective c++ 3
 
More Effective C++ 4주차
More Effective C++ 4주차More Effective C++ 4주차
More Effective C++ 4주차
 
이펙티브 C++ 5,6 장 스터디
이펙티브 C++ 5,6 장 스터디이펙티브 C++ 5,6 장 스터디
이펙티브 C++ 5,6 장 스터디
 
[HaU] 신입 기술 면접 준비 java
[HaU] 신입 기술 면접 준비 java[HaU] 신입 기술 면접 준비 java
[HaU] 신입 기술 면접 준비 java
 
Working Effectively With Legacy Code - xp2005
Working Effectively With Legacy Code - xp2005Working Effectively With Legacy Code - xp2005
Working Effectively With Legacy Code - xp2005
 
카사 공개세미나1회 W.E.L.C.
카사 공개세미나1회  W.E.L.C.카사 공개세미나1회  W.E.L.C.
카사 공개세미나1회 W.E.L.C.
 

C++ 2학기 수행평가