Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12111

Create Clamped Datatype

$
0
0

I want to create a c++ datatype that will always clamp it's value between 0.0 and 360.0. Other than that, it should behave exactly as a double. I would use it like this:

degree my_num1 = 3.5;   //my_num1 will equal 3.5degree my_num2 = 400.8;   //my_num2 will equal 360.0degree my_num3 = -5.1;   //my_num3 will equal 0.0

I have tried defining a template class, but I couldn't figure out how to make it work. typedef seems too limited, and I don't think struct will work either. I know that I can make a class and use getters and setters, but I really don't want to do that. Sorry if the answer is obvious, I am pretty new to c++. Also, I am using c++17.


Viewing all articles
Browse latest Browse all 12111

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>