Simply enough I'm writing a math library that detects the abilities of the CPU (whether it has 3DNow, SSE, etc) and then modifies the behaviour of some class members to utilise an optimal implementation. I'm having trouble setting up the pointers correctly. I have the class definition
Code:
class O3DMVector {
public:
float x, y, z, w;
O3DMVector() {
x = 0.0f; y = 0.0f; z = 0.0f; w = 1.0f;
}
inline float getLength() {
return (*getLengthPtr)(*this);
}
private:
static float (*getLengthPtr)(O3DMVector &);
};
I also have some implementation details
Code:
float cGetLength(O3DMVector &v);
float (O3DMVector::*getLengthPtr)(O3DMVector &) = &cGetLength;
float cGetLength(O3DMVector &v) {
return sqrt(v.x * v.x + v.y * v.y + v.z * v.z);
}
This gives me the error output
Code:
O3DMVector.cpp:5: error: cannot convert ‘float (*)(O3DMVector&)’ to ‘float (O3DMVector::*)(O3DMVector&)’ in initialization
I've tried modifying line 5 to read
Code:
float O3DMVector::(*getLengthPtr)(O3DMVector &) = &cGetLength;
This gives a different error
Code:
O3DMVector.cpp:5: error: expected unqualified-id before ‘(’ token
Anyone know what I have to do to get this working?