{"id":24692726,"url":"https://github.com/nigeparis/42-cpp-04","last_synced_at":"2026-05-19T04:40:15.925Z","repository":{"id":273895193,"uuid":"917031683","full_name":"NigeParis/42-cpp-04","owner":"NigeParis","description":"The Scope of this Module was to get to know C++ further and come in closer contact with inheritance for classes:","archived":false,"fork":false,"pushed_at":"2025-02-12T13:34:35.000Z","size":76,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-12T14:48:22.934Z","etag":null,"topics":["cpp"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/NigeParis.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-01-15T08:16:26.000Z","updated_at":"2025-02-12T13:42:37.000Z","dependencies_parsed_at":"2025-01-23T16:43:31.699Z","dependency_job_id":null,"html_url":"https://github.com/NigeParis/42-cpp-04","commit_stats":null,"previous_names":["nigeparis/42-cpp-04"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NigeParis%2F42-cpp-04","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NigeParis%2F42-cpp-04/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NigeParis%2F42-cpp-04/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NigeParis%2F42-cpp-04/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/NigeParis","download_url":"https://codeload.github.com/NigeParis/42-cpp-04/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244894317,"owners_count":20527678,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cpp"],"created_at":"2025-01-26T20:17:04.912Z","updated_at":"2026-05-19T04:40:10.900Z","avatar_url":"https://github.com/NigeParis.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Cpp - 04\n\n## About this Module\n\nThe Scope of this Module was to get to know C++ further and come in closer contact with inheritance for classes:\n\n- **ex00: Polymorphism**\n- **ex01: Creation of deep copies of classes**\n- **ex02: Introduction of the abstract class**\n\nAll of those exercises are compilable with the `-std=c++98` flag, since this was a requirement for this project.\nAll exercises were compiled and tested on macOS Catalina 10.15.7 and Ubuntu 20.04.4 LTS.\n\nAll exercises can be compiled from the root of the exercise with `make`, `make all` or `make re`.\nAll exercises have a main function to demonstrate all the abilities of the subject.\nAfter that, run the created executable like `./executable_to_run` (e.g., `ex00 ./Polymorphism`).\n\n## Key Concepts and Code Examples\n\n### ex00: Polymorphism\n\nPolymorphism allows derived classes to override base class methods to provide specific implementations.\n\n**Example:**\n```cpp\n#include \u003ciostream\u003e\n\nclass Animal {\npublic:\n    virtual void makeSound() const {\n        std::cout \u003c\u003c \"Some generic animal sound\" \u003c\u003c std::endl;\n    }\n};\n\nclass Dog : public Animal {\npublic:\n    void makeSound() const override {\n        std::cout \u003c\u003c \"Bark\" \u003c\u003c std::endl;\n    }\n};\n\nint main() {\n    Animal* animal = new Dog();\n    animal-\u003emakeSound(); // Output: Bark\n    delete animal;\n    return 0;\n}\n```\nex01: Creation of Deep Copies of Classes\n\nDeep copying involves creating a new object that is a copy of an existing object, including all dynamically allocated memory.\n\nExample:\n\n```c\n#include \u003ciostream\u003e\n#include \u003ccstring\u003e\n\nclass String {\nprivate:\n    char* str;\npublic:\n    String(const char* s) {\n        str = new char[strlen(s) + 1];\n        strcpy(str, s);\n    }\n\n    String(const String\u0026 other) {\n        str = new char[strlen(other.str) + 1];\n        strcpy(str, other.str);\n    }\n\n    ~String() {\n        delete[] str;\n    }\n\n    void print() const {\n        std::cout \u003c\u003c str \u003c\u003c std::endl;\n    }\n};\n\nint main() {\n    String hello(\"Hello\");\n    String copy = hello;\n    copy.print(); // Output: Hello\n    return 0;\n}\n```\nex02: Introduction of the Abstract Class\n\nAbstract classes serve as blueprints for derived classes and contain pure virtual functions.\n\nExample:\n\n```c\n#include \u003ciostream\u003e\n\nclass Shape {\npublic:\n    virtual double area() const = 0; // Pure virtual function\n};\n\nclass Circle : public Shape {\nprivate:\n    double radius;\npublic:\n    Circle(double r) : radius(r) {}\n    double area() const override {\n        return 3.14159 * radius * radius;\n    }\n};\n\nint main() {\n    Shape* shape = new Circle(5.0);\n    std::cout \u003c\u003c \"Area: \" \u003c\u003c shape-\u003earea() \u003c\u003c std::endl; // Output: Area: 78.5398\n    delete shape;\n    return 0;\n}\n```\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnigeparis%2F42-cpp-04","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnigeparis%2F42-cpp-04","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnigeparis%2F42-cpp-04/lists"}