I would strong advise against trying to build a li-ion battery charger. Charging such a battery is a complicated process. it has a constant current and constant voltage phase. It requires accurate measurement of voltage and current.
See "Charge and discharge procedure" here: https://en.wikipedia.org/wiki/Lithium-i ... _discharge
Note the statement "Failure to follow current and voltage limitations can result in an explosion."
It would also be wise to monitor battery temperature whilst charging. See notes on temperature in the above link.
Apart from all that there are ready made, working out of the box, charger boards available, with proper control chips on them. They are very cheap. Probably cheaper than building your own.
If, despite all that, you really, really want to build your own charger then a Pi is not an appropriate device to control it.
Memory in C++ is a leaky abstraction .