CPP Modules
42 Abu Dhabi

CPP Modules

Advanced C++ Programming

8 weeks
Individual Project
C++OOPSTLTemplates

Comprehensive C++ programming exercises covering object-oriented programming concepts, STL usage, templates, and advanced C++ features through practical implementations.

Key Features

Object-Oriented Design

Implemented classes with proper encapsulation, inheritance, and polymorphism following OOP principles.

STL Integration

Utilized Standard Template Library containers, algorithms, and iterators for efficient data manipulation.

Template Programming

Developed generic functions and classes using templates for type-safe and reusable code components.

Exception Handling

Implemented robust error handling with custom exceptions and RAII patterns for resource management.

Development Journey

Modules 00-02

C++ Fundamentals & Classes

Introduction to C++ syntax, classes, constructors, destructors, and basic OOP concepts. Implemented canonical class forms and member functions.

Modules 03-05

Inheritance & Polymorphism

Advanced OOP concepts including inheritance hierarchies, virtual functions, abstract classes, and polymorphic behavior implementation.

Modules 06-08

Advanced C++ Features

Explored templates, function pointers, iterators, and advanced STL usage. Implemented custom containers and algorithms.

Module 09

STL Mastery & Optimization

Deep dive into STL containers, algorithms, and performance optimization. Implemented complex data structures and sorting algorithms.

Challenges & Solutions

Memory Management

Problem:

Transitioning from C-style memory management to C++ RAII and smart pointers while avoiding memory leaks.

Solution:

Studied modern C++ practices and implemented proper RAII patterns with smart pointer usage.

Template Complexity

Problem:

Understanding template metaprogramming and resolving complex template compilation errors and syntax.

Solution:

Gradually built understanding through simple examples and progressively more complex template implementations.

STL Mastery

Problem:

Learning extensive STL library with its containers, algorithms, and iterator patterns for optimal usage.

Solution:

Systematic study of STL documentation and implementation of custom STL-like containers for deeper understanding.

template_container.hpp
cpp
template <typename T>
class Vector {
private:
    T*          _data;
    size_t      _size;
    size_t      _capacity;

public:
    class iterator {
    private:
        T* _ptr;
    public:
        iterator(T* ptr) : _ptr(ptr) {}
        T& operator*() { return *_ptr; }
        iterator& operator++() { ++_ptr; return *this; }
        bool operator!=(const iterator& other) const {
            return _ptr != other._ptr;
        }
    };

    Vector() : _data(nullptr), _size(0), _capacity(0) {}
    
    ~Vector() { 
        delete[] _data; 
    }
    
    void push_back(const T& value) {
        if (_size >= _capacity) {
            reserve(_capacity == 0 ? 1 : _capacity * 2);
        }
        _data[_size++] = value;
    }
    
    iterator begin() { return iterator(_data); }
    iterator end() { return iterator(_data + _size); }
};