about no matching function for call to
I am working on an old program. When I use old gcc version to compile the program, it works well, but when I use new gcc version, the program doesn't work. the program is as follows, and the error is "no matching function for call to divide(Vector3D,Vector3D&)".
Code:
struct Vector3D {
double x, y, z;
Vector3D () {}
Vector3D (double x, double y, double z) {
this->x = x; this->y = y; this->z = z;
}
Vector3D (const SmallVector3D& v);
...........
friend Vector3D divide (const Vector3D& p1, const Vector3D& p2) {
return Vector3D (p1.x / p2.x, p1.y / p2.y, p1.z / p2.z);
}
class BucketTable3D {
protected:
int _nGrids [ 3 ];
Vector3D _min, _max;
Vector3D _gridWidth;
public:
int* nGrids() { return _nGrids; }
virtual void indicesAt ( const Vector3D& position, int& x, int& y, int& z )
{
Vector3D n = ::divide ( position - _min, _gridWidth );
x = (int) n.x; y = (int) n.y; z = (int) n.z;
........
}
Thanks for your kindly help!
Alain
Re: about no matching function for call to
If this divide is declared inside Vector3D class, then it makes no sense - x,y,z are public, so every method can access those variables without having to be declared as "friend". To fix this, you can for example mark this method as "static" inside Vector3D class and call it like this:
Code:
Vector3D n = Vector3D::divide ( position - _min, _gridWidth );
Or simply move this method outside Vector3D class (this way you can keep the old calls).