pellep
asked on
easy points class member access
Can you access private memeber data/functions from static member function
class X
{
private:
int MyVal
public:
static void MyStatic(X *cls)
{
cls->MyVal=10;
}
void DoStaticStuff()
{
X::MyStatic(this);
}
};
int main()
{
X MyX
MyX.DoStaticStuff();
}
class X
{
private:
int MyVal
public:
static void MyStatic(X *cls)
{
cls->MyVal=10;
}
void DoStaticStuff()
{
X::MyStatic(this);
}
};
int main()
{
X MyX
MyX.DoStaticStuff();
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks. Short and to the point (I guess easy questions merits easy answers).
ASKER
The reason for the odd construction is deliberate. MyStatic is used in a call to CreateThread(), passing 'this' as the startup argument. (of course, in real life it would look sligthly different).
Out of curiousity, why did you code it that way? i.e why make MyStatic() static. That would be a good funciton to have as non-staitc. Was it just for an example?