Lesson 40 of 45 · C++
Lesson 45: Modules and Final Project Overview
Duration: 15 min
Lesson 40 of 45 · C++
Duration: 15 min
export module name;) declares what is exported.\n- Implementation unit (module name;) provides definitions.\n- Import with import name; instead of #include.\n\n## Example: Simple math module\ncpp\n// math.ixx – interface unit\nexport module math;\nexport int add(int a, int b) {\n return a + b;\n}\nexport int mul(int a, int b);\n\ncpp\n// math.cpp – implementation unit\nmodule math;\nint mul(int a, int b) {\n return a * b;\n}\n\ncpp\n// main.cpp – consumer\nimport <iostream>;\nimport math;\nint main() {\n std::cout << \"3+4 = \" << add(3,4) << '\\n';\n std::cout << \"3*4 = \" << mul(3,4) << '\\n';\n return 0;\n}\n\n\n## Final Project: Console Adventure Game\nYour capstone combines many concepts learned:\n- Classes (Player, Enemy, Map), inheritance, virtual functions.\n- Smart pointers for resource management.\n- STL containers (vector, map) for game state.\n- Filesystem for saving/loading progress.\n- Optional use of modules to split the codebase.\n\nProject roadmap:\n1. Design the data model (entities, items, map).\n2. Implement core gameplay loop with input handling.\n3. Add persistence using file I/O.\n4. (Optional) Refactor into modules.\n5. Write unit tests using the provided practical tests.\n\n> Tip: Start small – get a prototype working before adding advanced features like concurrency or networking.\n\n---\n\n<Alert type="info">Completing the project earns you the highest XP reward and a badge for "C++ Master".