static variables inside a member function
I want to boost up my "PointPointDistance" function (and all the others) with static variables. This function is a member function of a class. How can I create a variable inside this function if I want it to be static BUT only inside a created object. I mean, if I try this:
float U3DGeometry::UDistanceTester::PointPoint(const UPoint &p1, const UPoint &p2) const
{
static int call = 0;
call ++;
static UVector p1p2(p2.x - p1.x, p2.y - p1.y, p2.z - p1.z);
return p1p2.Length();
}
and then:
U3DGeometry::UDistanceTester a,b;
a.PointPoint(p,UPoint(0,0,0)); // Inside this function call the call variable is 0
a.PointPoint(p,UPoint(0,0,0)); // Inside this function call the call variable is 1
b.PointPoint(p,UPoint(1,1,1)); // Inside this function call the call variable is 2 <- I want this to be 0 because this is object "b"
a.PointPoint(p,UPoint(0,0,0)); // Inside this function call the call variable is 3
I make this whole thing because I want to create DistanceTester objects for every thread in my program (for those are using it). This would make it thread-safe and fast... I hope :)
Thank you for your help!
Hey, I don't think you can do it with static variables.. the point of static is to have the same value across all objects by defintition.
How about just a private member variable inside your class? Increment it each time PointPoint is called. The scope becomes wider than you need but i'm sure you can live with that.
How about just a private member variable inside your class? Increment it each time PointPoint is called. The scope becomes wider than you need but i'm sure you can live with that.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement