Thanks for the link. I wasn’t aware of this one 
It looks orthogonal to the choice of using a custom Function or not.
As mentioned above, if you c++ code is differentiable, you’re all good. If not, you’ll have to define the backward and can do so with a custom Function in python as instructed above that just happens to call you c++ code.