Retro Of Alexkid

여러 이야기
 by 알렉스키드
2023. 9. 15. 16:07 개발/C++
C++ 캐스트 연산자

#include <iostream>

using namespace std;

int main()
{
	int x = 2;
	double y = 4.4;
	
	int a = static_cast<int>(y/x);
	int b = (int) y / x;
	double c =  y / x;
	
	cout << a << endl;	
	cout << b << endl;	
	cout << c << endl;		
		
	return 0;
}

 

2
2
2.2

 

 

static_cast<> 가장 기본적인 캐스트 연산 방법
dinamic_cast<> 객체지향의 다형성을 이용하여 모호한 타앱 캐스팅 오류 막아줌
const_cast<> 자료형이 갖고 있는 상수 속성을 제거
reinterpret_cast<> 어떠한 포인터 타입끼리도 변환할 수 있게 도움

'개발 > C++' 카테고리의 다른 글

C++ 비트 연산  (0) 2023.09.14
C++ include  (0) 2023.08.30
C++ 네임스페이스  (0) 2023.08.29



Total / Today / Yesterday
Image by ポカポカ色
Tag by Passion
Designed by Ritz