GitHunt
HA

HamidMapna/Smart-Pointers-usage-in-polymorphism

This concise project, models the composite design pattern and utilizes the rvalue concept and smart pointer to benefit the move constructor performance advantages.

Rvalue Reference Usage

The main point of this small project lies in rvalue conceptual understanding, modeled in a composite design pattern.

I implemented mathematical expression calculation using composite design pattern which is based on polymorphism and calculate each part of expression in a recursive manner.
Example:

((10+(2*6))-5) = 17


I choiced to pass the arguments as rvalue reference to composite constructor and realized the virtual method of base class can't be resolved in runtime causing segmentaion fault. That's because the temporary memory bound of rvalue arguments to constructor arguments get destroyed afterwards.
Smart pointers are good solution for this problem, as they take ownership of thier object until they go out of thier scope. I used shared pointer to hold the ownership of composite instance.

A simple automatic test using google test framework was also implememted through github action workflow. You can find the YML file in .github/workflows path to find how to build a simple pipeline to manage build, test, atrifact creation and also publishing test results mechanisms.

Contributors

Created January 21, 2024
Updated January 23, 2024