vendredi 5 janvier 2018

use typedef for more type safe in c++

I would like to revisit the post. Currently, I am trying to avoid bug created by mixing Rad and Degree types for angles in my program.

For example:

  typedef float Degree;
  typedef float Radian;

  Degree a = 15.;

  Radian b = 3.14/4.;

  float c = a + b;  // no compile error

is there new update solution for this?

Aucun commentaire:

Enregistrer un commentaire