I want to do a angle class to be initialized in radians or degrees but i don’t know if it is a good idea. I’m thinking about something like this:
class Radian;
class Degree;
/**
* My angle class.
**/
class Angle
{
private:
float m_radian;
public:
explicit Angle(const Radian& rad);
explicit Angle(const Degree& deg);
float GetRadian(void) const
{
return this->m_radian;
}
float GetDegree(void) const
{
return ToDegree(this->m_radian);
}
bool IsEqual(const Angle& angle, float epsilon = 0.001f) const
{
return Abs<float>(this->m_radian - angle.m_radian) < epsilon;
}
void Set(const Angle& ang);
protected:
Angle(void) : m_radian(0.0f)
{}
Angle(float rad) : m_radian(rad)
{}
};
class Radian : public Angle
{
public:
Radian(void)
{}
Radian(float r) : Angle(r)
{}
};
class Degree : public Angle
{
public:
Degree(void)
{}
Degree(float d) : Angle(ToRadian(d))
{}
};
/// Trigonometric functions.
float Sin(const Angle& angle);
...
This way i won’t confuse radian and degrees in my code. But, is this a good idea or i should use other design?

I don’t see the need for inheritance here. As far as using your class is concerned, all that matters is that you get an angle – whether it was in degrees or radians to start with is irrelevant.
Disclaimer: I’ve done this before. Exactly the same use case. My solution was to make the constructor take two arguments: a number and a unit enum. I’d use my class like so:
If you want convenience methods to create angles from common units, they could be just that: helper methods. No need for separate classes.
Anyway – just what I’ve been happy using in the past. Hope it helps!