SlideShare a Scribd company logo
1 of 7
Download to read offline
C++ !
http://blog.naver.com/ruvendix
기본 생성자
사용자가 생성자를 정의하지 않으면 기본 생성자로 설정!
기본 생성자는 아무것도 안함!
class CTest
{
// 기본 생성자
CTest(void)
{
}
};
http://blog.naver.com/ruvendix
생성자 오버로딩
사용자는 생성자를 오버로딩해서 사용할 수 있다!
주로 객체를 초기화는 용도로 오버로딩함!
class CTest
{
CTest(void)
{
cout << “오버로딩”;
}
CTest(int iAge, const char *szName)
{
// 초기화 작업
}
};
http://blog.naver.com/ruvendix
변환 생성자
매개변수가 하나인 생성자를 변환 생성자라 함!
함수의 인자로 넘길 때 변환될 수 있으므로 변환 생성자라 함!
class CTest
{
CTest(int iAge)
{
// 초기화 작업
}
};
void Func(const Ctest &rCtest) { }
Func(5); // 이게 작동함!
http://blog.naver.com/ruvendix
explicit 예약어
변환 생성자에 제한을 걸려면 explicit 예약어를 사용해야 함!
explicit 예약어는 컴파일러가 묵시적 형변환을 하지 못하도록 막음!
class CTest
{
explicit CTest(int iAge)
{
// 초기화 작업
}
};
void Func(const Ctest &rCtest) { }
Func(5); // 이제는 작동 불가!
http://blog.naver.com/ruvendix
복사 생성자
복사 생성자는 함수의 인자로 넘길 때 많이 호출됨!
기본 복사 생성자는 얕은 복사를 한다는 단점이 있음!
class CTest
{
CTest(const Ctest &rCTest)
{
// 초기화 작업
}
};
CTest Test1;
CTest Test2(Test1); // 복사 생성자 호출!
복사 생성자는 기본 복사 생성자가 존재함!
http://blog.naver.com/ruvendix

More Related Content

What's hot

Hello c++ world
Hello c++ worldHello c++ world
Hello c++ world. Ruvendix
 
More effective c++ chapter1 2_dcshin
More effective c++ chapter1 2_dcshinMore effective c++ chapter1 2_dcshin
More effective c++ chapter1 2_dcshinDong Chan Shin
 
Geveloper 160816
Geveloper 160816Geveloper 160816
Geveloper 160816Nyeong Ahn
 
모어이펙티브 C++ 3,4장 예외, 효율 스터디
모어이펙티브 C++ 3,4장 예외, 효율 스터디모어이펙티브 C++ 3,4장 예외, 효율 스터디
모어이펙티브 C++ 3,4장 예외, 효율 스터디quxn6
 
More effective c++ 2
More effective c++ 2More effective c++ 2
More effective c++ 2현찬 양
 
M1 2 1
M1 2 1M1 2 1
M1 2 1nexthw
 
자바와 사용하기2
자바와 사용하기2자바와 사용하기2
자바와 사용하기2destinycs
 
팩토리 메소드 패턴과 추상 팩토리 패턴
팩토리 메소드 패턴과 추상 팩토리 패턴팩토리 메소드 패턴과 추상 팩토리 패턴
팩토리 메소드 패턴과 추상 팩토리 패턴GeniusYG
 
이펙티브 C++ 공부
이펙티브 C++ 공부이펙티브 C++ 공부
이펙티브 C++ 공부quxn6
 
More effective c++ 항목30부터
More effective c++ 항목30부터More effective c++ 항목30부터
More effective c++ 항목30부터Dong Chan Shin
 
이펙티브 C++ 5,6 장 스터디
이펙티브 C++ 5,6 장 스터디이펙티브 C++ 5,6 장 스터디
이펙티브 C++ 5,6 장 스터디quxn6
 
포스트모템디버깅과 프로세스 덤프 실전
포스트모템디버깅과 프로세스 덤프 실전포스트모템디버깅과 프로세스 덤프 실전
포스트모템디버깅과 프로세스 덤프 실전주항 박
 

What's hot (20)

Hello c++ world
Hello c++ worldHello c++ world
Hello c++ world
 
Start groovy
Start groovyStart groovy
Start groovy
 
More effective c++ chapter1 2_dcshin
More effective c++ chapter1 2_dcshinMore effective c++ chapter1 2_dcshin
More effective c++ chapter1 2_dcshin
 
Geveloper 160816
Geveloper 160816Geveloper 160816
Geveloper 160816
 
모어이펙티브 C++ 3,4장 예외, 효율 스터디
모어이펙티브 C++ 3,4장 예외, 효율 스터디모어이펙티브 C++ 3,4장 예외, 효율 스터디
모어이펙티브 C++ 3,4장 예외, 효율 스터디
 
More effective c++ 2
More effective c++ 2More effective c++ 2
More effective c++ 2
 
M1 2 1
M1 2 1M1 2 1
M1 2 1
 
자바와 사용하기2
자바와 사용하기2자바와 사용하기2
자바와 사용하기2
 
C++11 1
C++11 1C++11 1
C++11 1
 
javascript01
javascript01javascript01
javascript01
 
팩토리 메소드 패턴과 추상 팩토리 패턴
팩토리 메소드 패턴과 추상 팩토리 패턴팩토리 메소드 패턴과 추상 팩토리 패턴
팩토리 메소드 패턴과 추상 팩토리 패턴
 
이펙티브 C++ 공부
이펙티브 C++ 공부이펙티브 C++ 공부
이펙티브 C++ 공부
 
More effective c++ 항목30부터
More effective c++ 항목30부터More effective c++ 항목30부터
More effective c++ 항목30부터
 
ES6-01
ES6-01ES6-01
ES6-01
 
이펙티브 C++ 5,6 장 스터디
이펙티브 C++ 5,6 장 스터디이펙티브 C++ 5,6 장 스터디
이펙티브 C++ 5,6 장 스터디
 
연산자
연산자연산자
연산자
 
포인터
포인터포인터
포인터
 
동적할당
동적할당동적할당
동적할당
 
01. basic types
01. basic types01. basic types
01. basic types
 
포스트모템디버깅과 프로세스 덤프 실전
포스트모템디버깅과 프로세스 덤프 실전포스트모템디버깅과 프로세스 덤프 실전
포스트모템디버깅과 프로세스 덤프 실전
 

Viewers also liked

Viewers also liked (10)

형식 선정
형식 선정형식 선정
형식 선정
 
클래스의 기초 지식
클래스의 기초 지식클래스의 기초 지식
클래스의 기초 지식
 
템플릿
템플릿템플릿
템플릿
 
배열
배열배열
배열
 
SÃO JOSÉ Esposo da Santíssima Virgem
SÃO JOSÉ Esposo da Santíssima VirgemSÃO JOSÉ Esposo da Santíssima Virgem
SÃO JOSÉ Esposo da Santíssima Virgem
 
구조체
구조체구조체
구조체
 
자료형과 값
자료형과 값자료형과 값
자료형과 값
 
Geestelijke gaven
Geestelijke gavenGeestelijke gaven
Geestelijke gaven
 
Investment strategies
Investment strategiesInvestment strategies
Investment strategies
 
Business harvesting
Business harvestingBusiness harvesting
Business harvesting
 

Similar to 여러 생성자

[C++ Korea] Effective Modern C++ mva item 7 distinguish between and {} when c...
[C++ Korea] Effective Modern C++ mva item 7 distinguish between and {} when c...[C++ Korea] Effective Modern C++ mva item 7 distinguish between and {} when c...
[C++ Korea] Effective Modern C++ mva item 7 distinguish between and {} when c...Seok-joon Yun
 
불어오는 변화의 바람, From c++98 to c++11, 14
불어오는 변화의 바람, From c++98 to c++11, 14 불어오는 변화의 바람, From c++98 to c++11, 14
불어오는 변화의 바람, From c++98 to c++11, 14 명신 김
 
[C++ korea] effective modern c++ study item 7 distinguish between () and {} w...
[C++ korea] effective modern c++ study item 7 distinguish between () and {} w...[C++ korea] effective modern c++ study item 7 distinguish between () and {} w...
[C++ korea] effective modern c++ study item 7 distinguish between () and {} w...Seok-joon Yun
 
Visual studio 2010
Visual studio 2010Visual studio 2010
Visual studio 2010MinGeun Park
 
[C++ Korea] Effective Modern C++ Study item14 16 +신촌
[C++ Korea] Effective Modern C++ Study item14 16 +신촌[C++ Korea] Effective Modern C++ Study item14 16 +신촌
[C++ Korea] Effective Modern C++ Study item14 16 +신촌Seok-joon Yun
 
120908 레거시코드활용전략 4장5장
120908 레거시코드활용전략 4장5장120908 레거시코드활용전략 4장5장
120908 레거시코드활용전략 4장5장tedypicker
 
C++ Advanced 강의 2주차
C++ Advanced 강의 2주차C++ Advanced 강의 2주차
C++ Advanced 강의 2주차HyunJoon Park
 
C++ 프로젝트에 단위 테스트 도입하기
C++ 프로젝트에 단위 테스트 도입하기C++ 프로젝트에 단위 테스트 도입하기
C++ 프로젝트에 단위 테스트 도입하기Heo Seungwook
 
[2011 04 11]mock_object 소개
[2011 04 11]mock_object 소개[2011 04 11]mock_object 소개
[2011 04 11]mock_object 소개Jong Pil Won
 
Sonarqube 20160509
Sonarqube 20160509Sonarqube 20160509
Sonarqube 20160509영석 조
 
Boost라이브러리의내부구조 20151111 서진택
Boost라이브러리의내부구조 20151111 서진택Boost라이브러리의내부구조 20151111 서진택
Boost라이브러리의내부구조 20151111 서진택JinTaek Seo
 
Nexon Developers Conference 2017 Functional Programming for better code - Mod...
Nexon Developers Conference 2017 Functional Programming for better code - Mod...Nexon Developers Conference 2017 Functional Programming for better code - Mod...
Nexon Developers Conference 2017 Functional Programming for better code - Mod...Isaac Jeon
 
2014-15 Intermediate C++ Study #6
2014-15 Intermediate C++ Study #62014-15 Intermediate C++ Study #6
2014-15 Intermediate C++ Study #6Chris Ohk
 
React 애플리케이션 아키텍처 - 아무도 알려주지 않아서 혼자서 삽질했다.
React 애플리케이션 아키텍처 - 아무도 알려주지 않아서 혼자서 삽질했다.React 애플리케이션 아키텍처 - 아무도 알려주지 않아서 혼자서 삽질했다.
React 애플리케이션 아키텍처 - 아무도 알려주지 않아서 혼자서 삽질했다.병대 손
 
More effective c++ chapter1,2
More effective c++ chapter1,2More effective c++ chapter1,2
More effective c++ chapter1,2문익 장
 
포트폴리오에서 사용한 모던 C++
포트폴리오에서 사용한 모던 C++포트폴리오에서 사용한 모던 C++
포트폴리오에서 사용한 모던 C++KWANGIL KIM
 
10장 결과 검증
10장 결과 검증10장 결과 검증
10장 결과 검증dagri82
 
Effective c++(chapter 5,6)
Effective c++(chapter 5,6)Effective c++(chapter 5,6)
Effective c++(chapter 5,6)문익 장
 
About Visual C++ 10
About  Visual C++ 10About  Visual C++ 10
About Visual C++ 10흥배 최
 
Angular2 가기전 Type script소개
 Angular2 가기전 Type script소개 Angular2 가기전 Type script소개
Angular2 가기전 Type script소개Dong Jun Kwon
 

Similar to 여러 생성자 (20)

[C++ Korea] Effective Modern C++ mva item 7 distinguish between and {} when c...
[C++ Korea] Effective Modern C++ mva item 7 distinguish between and {} when c...[C++ Korea] Effective Modern C++ mva item 7 distinguish between and {} when c...
[C++ Korea] Effective Modern C++ mva item 7 distinguish between and {} when c...
 
불어오는 변화의 바람, From c++98 to c++11, 14
불어오는 변화의 바람, From c++98 to c++11, 14 불어오는 변화의 바람, From c++98 to c++11, 14
불어오는 변화의 바람, From c++98 to c++11, 14
 
[C++ korea] effective modern c++ study item 7 distinguish between () and {} w...
[C++ korea] effective modern c++ study item 7 distinguish between () and {} w...[C++ korea] effective modern c++ study item 7 distinguish between () and {} w...
[C++ korea] effective modern c++ study item 7 distinguish between () and {} w...
 
Visual studio 2010
Visual studio 2010Visual studio 2010
Visual studio 2010
 
[C++ Korea] Effective Modern C++ Study item14 16 +신촌
[C++ Korea] Effective Modern C++ Study item14 16 +신촌[C++ Korea] Effective Modern C++ Study item14 16 +신촌
[C++ Korea] Effective Modern C++ Study item14 16 +신촌
 
120908 레거시코드활용전략 4장5장
120908 레거시코드활용전략 4장5장120908 레거시코드활용전략 4장5장
120908 레거시코드활용전략 4장5장
 
C++ Advanced 강의 2주차
C++ Advanced 강의 2주차C++ Advanced 강의 2주차
C++ Advanced 강의 2주차
 
C++ 프로젝트에 단위 테스트 도입하기
C++ 프로젝트에 단위 테스트 도입하기C++ 프로젝트에 단위 테스트 도입하기
C++ 프로젝트에 단위 테스트 도입하기
 
[2011 04 11]mock_object 소개
[2011 04 11]mock_object 소개[2011 04 11]mock_object 소개
[2011 04 11]mock_object 소개
 
Sonarqube 20160509
Sonarqube 20160509Sonarqube 20160509
Sonarqube 20160509
 
Boost라이브러리의내부구조 20151111 서진택
Boost라이브러리의내부구조 20151111 서진택Boost라이브러리의내부구조 20151111 서진택
Boost라이브러리의내부구조 20151111 서진택
 
Nexon Developers Conference 2017 Functional Programming for better code - Mod...
Nexon Developers Conference 2017 Functional Programming for better code - Mod...Nexon Developers Conference 2017 Functional Programming for better code - Mod...
Nexon Developers Conference 2017 Functional Programming for better code - Mod...
 
2014-15 Intermediate C++ Study #6
2014-15 Intermediate C++ Study #62014-15 Intermediate C++ Study #6
2014-15 Intermediate C++ Study #6
 
React 애플리케이션 아키텍처 - 아무도 알려주지 않아서 혼자서 삽질했다.
React 애플리케이션 아키텍처 - 아무도 알려주지 않아서 혼자서 삽질했다.React 애플리케이션 아키텍처 - 아무도 알려주지 않아서 혼자서 삽질했다.
React 애플리케이션 아키텍처 - 아무도 알려주지 않아서 혼자서 삽질했다.
 
More effective c++ chapter1,2
More effective c++ chapter1,2More effective c++ chapter1,2
More effective c++ chapter1,2
 
포트폴리오에서 사용한 모던 C++
포트폴리오에서 사용한 모던 C++포트폴리오에서 사용한 모던 C++
포트폴리오에서 사용한 모던 C++
 
10장 결과 검증
10장 결과 검증10장 결과 검증
10장 결과 검증
 
Effective c++(chapter 5,6)
Effective c++(chapter 5,6)Effective c++(chapter 5,6)
Effective c++(chapter 5,6)
 
About Visual C++ 10
About  Visual C++ 10About  Visual C++ 10
About Visual C++ 10
 
Angular2 가기전 Type script소개
 Angular2 가기전 Type script소개 Angular2 가기전 Type script소개
Angular2 가기전 Type script소개
 

여러 생성자