...it simply cannot be done without rebooting; some commands such as
require a reboot to not break the system...
I'm very sure this is not true.
pivpn is only installing and configuring openvpn. I know from experience that this does not require a reboot to get working.
Further, when installing/upgrading things with apt-get and friends a reboot is almost never required. Only when the kernel is upgraded. Given that it's unlikely you need to do a reboot.
As for how to deal with the reboot solution with a script. The idea is of creating a file as a flag that a reboot has occurred is pretty solid. Suggest learning how to use BASH. There are thousands of documents, tutorials, discussions, etc all over the net on BASH scripting.
Memory in C++ is a leaky abstraction .