How to change material for a mesh in cpp?

Thanks, this is useful.