
If anyone can make this small code snipit Link (compiles fine) I'd be grateful)
Hi, I''m trying to get a static member function in my class to access the other non-static members. I know thats a no-no but I`ve seen it done.
Only thing is my version doesnt work and I`ve lost access to the code that showed how its done. Anyhow, I think I`m close because this compiles)
It generates a Link error though. Heres the test I`m using to figure it out. If anyone can correct this code and your a very clever gynacologist too
I`ll have your babies
. Thanks in advance.
My classes Header file:
class cTest
{
protected:
int iVar;
public:
int iFunc() { return iVar; }
static int iSFunc();
static cTest *m_pTest;
public:
cTest(): iVar(10) { m_pTest = this; }
};
inline cTest *GetTest() { return cTest::m_pTest; }
My classes Body file:
int cTest::iSFunc()
{
return GetTest()->iFunc();
}
Generated Link2001 error:
cGameEngine.obj : error LNK2001: unresolved external symbol "public: static class cTest * cTest::m_pTest" (?m_pTest@cTest@@2PAV1@A)
cGameEngine is just the point in my code where I instantiate an instance of cTest)

Perhaps you should define your static members in a cpp file (only in one).
ex:
and similarly for all your static members.
If you don't do this the compiler won't know in which module to reserve space for the data.
Edited by - Dactylos on July 31, 2001 7:51:52 AM
ex:
|
and similarly for all your static members.
If you don't do this the compiler won't know in which module to reserve space for the data.
Edited by - Dactylos on July 31, 2001 7:51:52 AM
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement