I have a small class with the following member functions:
class Point3 {
Point3 operator - (Point3 const & p) const {...}
Point3 operator - () const {...}
const float &x() const {...}
float& x() {...}
}
I need to pass to pass these member functions as arguments to other functions, and of course using just &Point3::operator-
and &Point3::x
does not work.
Looking to similar questions online, I concluded that the syntax for making this kind of casts is (ReturnType (Class::*)(Args...)) &Class::Function
. However, I tried for the binary operator - without success.
(Point3 (Point3::*)(Point3 const &)) &Point3::operator-
gives error: address of overloaded function 'operator-' does not match required type 'Point3 (const Point3 &)' note: candidate function has different qualifiers (expected unqualified but found 'const') [...]
For the x()
member function I just don't have idea on where place the const related to the member function. How can I disambiguate these member functions?
Aucun commentaire:
Enregistrer un commentaire