[C++] Member function headache
From: Heikki Salo (heikki_salo_at_nobulkmailplease.sci.fi)
Date: 11/21/03
- Next message: mike: "Re: The thorny issue of main's return type (WAS: Top ten errors)"
- Previous message: glen herrmannsfeldt: "Re: Theoretical Problem"
- Next in thread: André Pönitz: "Re: [C++] Member function headache"
- Reply: André Pönitz: "Re: [C++] Member function headache"
- Reply: Karl Heinz Buchegger: "Re: [C++] Member function headache"
- Reply: ellie fant: "Re: [C++] Member function headache"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 21 Nov 2003 11:30:09 +0200
I am designing a geometry class collection (for personal use) and I have
encountered a little problem. It is not technical, but still annoying. I
have an abstract base class wich has some methods that must be overrided in
the derived class. There is one overloaded function to check if two areas
overlap (areas can be rectangles, circles, points...).
class Area {
public:
bool overlap(Rectangle&) = 0;
bool overlap(Circle&) = 0;
... // more functions for another type of areas
};
The problem is that when I have a rectangle class which has an overlap
funtion defined for circle, I have to define circle an overlap function for
rectangle. The functions are almost completely identical. One solution is to
make circles overlap funtion like this:
bool Circle::overlap(Rectangle& rect) {
return rect.overlap(*this);
}
I believe that virtual functions can not be inlined (?), so the previous
solution wastes some time. I could also put the same code in both functions,
but it just does not feel right. Any good ideas?
I have also another question conserning pass-by-reference, which those
funtions use. C++ FAQLite says that pass-by-value can be faster, which was
quite a surprise for me. Should I use pass by reference or value?
- Next message: mike: "Re: The thorny issue of main's return type (WAS: Top ten errors)"
- Previous message: glen herrmannsfeldt: "Re: Theoretical Problem"
- Next in thread: André Pönitz: "Re: [C++] Member function headache"
- Reply: André Pönitz: "Re: [C++] Member function headache"
- Reply: Karl Heinz Buchegger: "Re: [C++] Member function headache"
- Reply: ellie fant: "Re: [C++] Member function headache"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|