Fix casts for C++ compiler