Skip to content

natamun/42-cpp06

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

42-cpp06

The seventh C++ module of the 42 curriculum, focused on C++ casts.

This project covers the four explicit cast operators of C++ and the scenarios where each is appropriate: type conversion, serialization, and runtime type identification.

Usage

Each exercise (ex00 to ex02) contains its own Makefile. Compile and run individually:

cd ex00
make
./ex00

Exercises

  • ex00: ScalarConverter — converts a string literal to char, int, float, and double using static_cast, handling special values (nan, inf, non-displayable characters).
  • ex01: Serializer — converts a pointer to uintptr_t and back using reinterpret_cast, demonstrating pointer serialization without data loss.
  • ex02: Type identification — given a randomly instantiated A, B, or C object through a Base*, identify the real type using dynamic_cast on both pointers and references.

Code Structure

Each exercise is self-contained in its own directory with its own source files, headers, and Makefile, following the standard 42 module layout.

About

Type casting in C++: static, reinterpret, and dynamic cast operators

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Contributors