Convert miscres.c to C++