c++ 형변환 연산자

1. static_cast

// 기본 타입 변환
int a = 10;
double b = static_cast<double>(a); // int -> double 변환

// 부모-자식 클래스 변환
class Base {};
class Derived : public Base {};

Base* base = new Derived();
Derived* derived = static_cast<Derived*>(base); // 부모 -> 자식 변환

2. dynamic_cast

class Base {
public:
    virtual ~Base() {} // 다형성을 위해 가상 소멸자가 필요
};

class Derived : public Base {};

Base* base = new Derived();
Derived* derived = dynamic_cast<Derived*>(base); // 성공: derived는 유효한 Derived 객체

3. const_cast