Right now I am using std::pair to represent a 2d point in c++. However, I am getting annoyed with having to write
typedef std::pair<double, double> Point;
Point difference = Point(p2.first - p1.first,
p2.second - p1.second);
instead of being able to overload operator+ and operator-.
So, my question is, to make my Point class, should I
- Publicly derive from std::pair and add my own member functions? This is nice because all my code can stay the same. I am not going to be doing anything like
std::pair<double, double>* p = new Point;
so I don't have to worry about things like virtual destructors. - Roll my own Point class, which is annoying since I am duplicating std::pair's functionality, however I am "doing it the pure way".
- Make template specializations of operator+ and operator- for std::pair, which admittedly I don't remember if they go in source or header files.
I guess it's up for debate, I'd really like to do #1 but I don't know if it's a bad idea since I've heard that inheriting from STL is a no-no.