J
Joe Van Dyk
Hi,
Say I have:
class Latitude
{
friend bool operator==(const Latitude& lhs, const Latitude& rhs);
friend bool operator<(const Latitude& lhs, const Latitude& rhs);
friend std:stream& operator<<(std:stream& os, const Latitude& l);
public:
explicit Latitude(double latitude);
double latitude() const { return latitude_; }
private:
double latitude_;
};
So, it's essentially a wrapper around a double. The constructor enforces
that the latitude can't be less than -90 or greater than 90. Comparison
operators do the comparison of the double.
Now, I've got to do the same with Longitude and Altitude. They're all
kinda the same, except that Longitude can range from -180 to 180, and
Altitude doesn't really have a limit (I guess its the limit on what a
double can hold).
How can I consolidate this logic? Templates? Inheritance? Or am I going
about this completely wrong?
Joe
Say I have:
class Latitude
{
friend bool operator==(const Latitude& lhs, const Latitude& rhs);
friend bool operator<(const Latitude& lhs, const Latitude& rhs);
friend std:stream& operator<<(std:stream& os, const Latitude& l);
public:
explicit Latitude(double latitude);
double latitude() const { return latitude_; }
private:
double latitude_;
};
So, it's essentially a wrapper around a double. The constructor enforces
that the latitude can't be less than -90 or greater than 90. Comparison
operators do the comparison of the double.
Now, I've got to do the same with Longitude and Altitude. They're all
kinda the same, except that Longitude can range from -180 to 180, and
Altitude doesn't really have a limit (I guess its the limit on what a
double can hold).
How can I consolidate this logic? Templates? Inheritance? Or am I going
about this completely wrong?
Joe