Hi,
We generally access non-static class members from a static method by passing
"this" to that static method and accessing non-static members over "this".
My alternative is caching "this" into a static member and use that static
member whenever you need to access non-static members. Is there anything bad
about this solution?
//////////////////////////////////////////////////// SAMPLE
///////////////////////////////////////
class Foo
{
public:
static Foo * lpThis;
Foo ()
{
// Some initializations...
lpThis = this; // Last statement in the constructor...
}
static void doJob ()
{
// Now we can access all non-static members over static "lpThis"...
}
};
Foo * Foo::lpThis;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
Thanks in advance.