A personal repository for learning C++ and Object-Oriented Programming, covering core concepts, examples, and hands-on practice.
This repository provides a structured approach to learning OOP concepts in C++. Each concept is organized in its own directory with examples, demonstrations, and exercises. The project includes automation scripts to quickly generate templates for new concepts and classes.
- CMake 3.15 or higher
- C++17 compatible compiler (GCC 7+, Clang 5+, MSVC 2017+, or Apple Clang)
- Python 3.6 or higher
cpp-oop-lab/
├── CMakeLists.txt # Root build configuration
├── README.md # This file
├── .gitignore # Git ignore rules
├── scripts/ # Automation scripts
│ ├── create_concept.py # Generate new concept template
│ └── create_class.py # Generate class/header pairs
└── concepts/ # All OOP concepts
├── basic_class/
│ ├── CMakeLists.txt
│ ├── main.cpp
│ ├── README.md
│ └── *.h, *.cpp
├── inheritance/
├── polymorphism/
└── ...
Generate a new concept directory with all necessary files:
python3 scripts/create_concept.py <concept_name> --description "Brief description"Example:
python3 scripts/create_concept.py inheritance --description "Demonstrating IS-A relationships"This creates:
concepts/inheritance/directorymain.cppwith demo templateCMakeLists.txtconfigured for the conceptREADME.mdwith concept details
Generate class and header files within a concept:
python3 scripts/create_class.py <concept_name> <ClassName>Example:
# Create base class
python3 scripts/create_class.py inheritance Animal
# Create derived class
python3 scripts/create_class.py inheritance Dog --base-class AnimalThis creates:
<ClassName>.hwith header guards and class declaration<ClassName>.cppwith constructor/destructor stubs- Automatic inheritance setup if
--base-classis specified
Build your concept:
# Initial setup (first time only)
mkdir -p build
cd build
cmake ..
# Build specific concept
make <concept_name>_demo
# Run it
./concepts/<concept_name>/<concept_name>_demoExample:
cd build
make inheritance_demo
./concepts/inheritance/inheritance_democd build
makeHere's a complete workflow for creating an inheritance example:
# 1. Create the concept
python3 scripts/create_concept.py inheritance --description "Demonstrating class inheritance"
# 2. Create base class
python3 scripts/create_class.py inheritance Animal
# 3. Create derived class
python3 scripts/create_class.py inheritance Dog --base-class Animal
# 4. Edit the generated files
# - Open concepts/inheritance/Animal.h and Animal.cpp
# - Open concepts/inheritance/Dog.h and Dog.cpp
# - Open concepts/inheritance/main.cpp
# - Implement your classes and demo code
# 5. Build
mkdir -p build && cd build
cmake ..
make inheritance_demo
# 6. Run
./concepts/inheritance/inheritance_demopython3 scripts/create_concept.py <concept_name> [options]
Arguments:
concept_name Name of the concept (e.g., polymorphism)
Options:
--description DESCRIPTION Brief description of the conceptpython3 scripts/create_class.py <concept_name> <class_name> [options]
Arguments:
concept_name Name of the concept directory
class_name Name of the class (e.g., Animal)
Options:
--base-class BASE_CLASS Base class for inheritance- No manual CMake editing required
- New concepts are auto-discovered when they contain
CMakeLists.txt - New classes are auto-included via glob patterns
- Just create files and rebuild
- Each concept is self-contained
- Separate executable per concept
- Easy to focus on one concept at a time
- Out-of-source builds (build/ directory)
- Proper header guards
- C++17 standards compliance
- Compiler warnings enabled
Suggested order for studying concepts:
- basic_class - Classes, objects, constructors, destructors
- encapsulation - Access specifiers, getters/setters
- inheritance - Base and derived classes, IS-A relationship
- polymorphism - Virtual functions, runtime polymorphism
- abstraction - Abstract classes, pure virtual functions
- composition - HAS-A relationship
- operator_overloading - Custom operators
- templates - Generic programming
- exception_handling - Try-catch blocks
- Each concept folder contains a
README.mdwith specific details - Start simple and gradually add complexity
- Run your demos frequently to verify behavior
- Use the compiler warnings to learn best practices
- Experiment and modify the examples
The root CMakeLists.txt automatically finds all concept directories:
- Scans
concepts/for subdirectories - Includes any directory with a
CMakeLists.txt - After creating a new concept, run
cmake ..to refresh
Executables are organized by concept:
build/
└── concepts/
├── basic_class/
│ └── basic_class_demo
├── inheritance/
│ └── inheritance_demo
└── ...
To start fresh:
rm -rf build
mkdir build
cd build
cmake ..
makeAfter creating a new concept, re-run CMake:
cd build
cmake ..Make sure you're using C++17 compatible compiler:
g++ --version # GCC 7+
clang++ --version # Clang 5+Ensure Python 3.6+:
python3 --versionThis is a personal learning repository, but feel free to fork and adapt for your own learning journey.
This project is for educational purposes. Feel free to use and modify as needed for learning.