42 Exam 05

Based on the filename/identifier "42 exam 05" , this refers to Exam Rank 05 of the École 42 curriculum. In the "Classic" 42 curriculum (Common Core), Exam Rank 05 is generally considered the easiest of the advanced ranks. It focuses on Object-Oriented Programming (OOP) in C++ . Here is a comprehensive guide to preparing for and passing Exam 05.

1. The Context: What is Exam 05?

Language: C++ (specifically C++98 standard). Allowed Tools: You are restricted to basic C++ features. You cannot use external libraries (like Boost) or modern C++ features (like smart pointers in C++11/14/17) unless the subject specifies otherwise. Constraint: You must compile with clang++ -Wall -Wextra -Werror -std=c++98 . Goal: Demonstrate understanding of Classes, Member Functions, and Canonical Form.

2. The Core Concepts Before you attempt the exam, you must have these concepts memorized and practiced. You will not have internet access to look them up. A. The Canonical Orthodox Form This is the "Golden Rule" of Exam 05. For almost every class you write, you must implement these four functions: 42 exam 05

Default Constructor: Initializes the class members. Copy Constructor: Creates a new object as a copy of an existing one. Copy Assignment Operator ( operator= ): Overwrites an existing object with the values of another. Destructor: Cleans up resources.

Example Skeleton: class MyClass { public: MyClass(void); // Default Constructor MyClass(MyClass const & src); // Copy Constructor ~MyClass(void); // Destructor MyClass & operator=(MyClass const & rhs); // Assignment Operator

};

B. Class Syntax Basics

Header Files ( .hpp ): Know how to guard headers ( #ifndef , #define , #endif ). this pointer: Understand that this refers to the current instance. const : Know where to put const .

After a member function declaration: int getValue(void) const; (Means the function does not modify the object). In parameters: void setName(std::string const & name); . Based on the filename/identifier "42 exam 05" ,

C. C++ Strings and IO

std::string : You will use this heavily. Know how to: