Overloading problem

Hello all,

I have a frustrating problem. I'm creating my own vector files (for some noise calculations, doesn't matter). I would LIKE to have a function for each vector type (Vector2df, Vector3df and Vector4df) that is called "floor". This is fully possible, no problem at all. When I try to implement the function, I would of course like to use the "floor" function in cmath on each element of the vector. But here is the problem: when I try to call the external floor-function from MY floor-function, the system complains. I get the same problem when I try to do a "max" function (STL algorithms). Here's the error:

1
2
./src/geometry/Vector3df.cpp:131: error: no matching function for call to ‘Vector3df::max(const float&, const float&) const’
./src/geometry/Vector3df.cpp:127: note: candidates are: Vector3df Vector3df::max(const Vector3df&) const


Why can is suddenly not recognize that the max (or floor) function exists? It feels like I'm missing out on something fairly basic here which is somewhat embarrassing. Now, of course, I CAN name the function "floorThis" or "floorMe" or something but I WANT to name them floor and SHOULD be able to do so, shouldn't I? If I change the function name to maxVec or floorVec, changing nothing else, it works just fine, so it's not that it can't find these functions to begin with.

So, in short, this works:

1
2
3
4
5
6
7
8
9
Vector3df Vector3df::maxVec(const Vector3df & vec) const
{
    Vector3df vecReturn;
    vecReturn.x = max(vec.x, x);
    vecReturn.y = max(vec.y, y);
    vecReturn.z = max(vec.z, z);

    return vecReturn;
}


... and this doesn't:


1
2
3
4
5
6
7
8
9
Vector3df Vector3df::max(const Vector3df & vec) const
{
    Vector3df vecReturn;
    vecReturn.x = max(vec.x, x);
    vecReturn.y = max(vec.y, y);
    vecReturn.z = max(vec.z, z);

    return vecReturn;
}


Could it be a matter of settings in the makefile? Or am I horrible lost?

I'd appreciate all help you could give me on this. Please ask if you need more information.

/Anvariel
What happens if you change max to std::max ?
That works brilliantly! =) Thank you. But what about the floor function? That isn't part of a namespace, right? Old C, and all that. For now I've solved it using floorf instead, but that is just not right. I should be able to use floor. I find it strange that there is a problem considering the function parameters are in no way the same.
::floor?
Hm! That works! Thank you very much! I have never come across that during my 5 years of C++ struggles. Maybe I would have if I hadn't cheated my way around solutions before. :)

Thank you!
Topic archived. No new replies allowed.