Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Preventing automatic casts with integers

I'm developing an audio application (in C++) and I have lots of functions that call each other that either take the number of frames (i.e. 1 mono or 2 stereo float samples) or the raw number of samples...

It is getting harder to keep track of the semantics of each function (samples or frames?) and when to mult or div by nChannels, so I would like to somehow do a typedef samples_t and frames_t (to unsigned int) and have the compiler help me out...

Is there any simple way to have an implicit conversion from frames_t to samples_t be marked as an error in C++?

like image 257
MikasMix Avatar asked Oct 21 '22 03:10

MikasMix


1 Answers

You could go all out and define your own system within boost.units, or alternatively just use the BOOST_STRONG_TYPEDEF macro to create a strong typedef for each type.

like image 179
dhavenith Avatar answered Oct 24 '22 02:10

dhavenith