static functions with non-static variables! 
Author Message
 static functions with non-static variables!

Hello All,

I have a little problem that i hope some of you might be able to help me
with.

Basically i have a class which contains a function declared as static:

// MyClass.h
class CMyClass
{
public:
// PUBLIC FUNCTIONS
        static BOOL MyStaticFunction(void);
// PUBLIC VARIABLES
        BOOL m_bDone;

Quote:
};

But the problem is i need to change the value of m_bDone in the function
MyClass::MyStaticFunction(). Like this ...

BOOL CMyClass::MyStaticFunction(void)
{
        m_bDone = FALSE;                // This generates a compiler error.
        CMyClass::m_bDone = FALSE;      // This generates a compiler error.

Quote:
}

If anyone knows a way around this problem, please get back to me either

Thanks in advance,

Conner.



Sun, 31 Dec 2000 03:00:00 GMT  
 static functions with non-static variables!
Will this work...

// MyClass.h
class CMyClass
{
public:
// PUBLIC FUNCTIONS
        static BOOL MyStaticFunction(CMyClass & o);
// PUBLIC VARIABLES
        BOOL m_bDone;

Quote:
};

BOOL CMyClass::MyStaticFunction(CMyClass & o)
{
        o.m_bDone = FALSE;

Quote:
}

But you must always pass a reference to the active instance.

--

The Programmer's Knowledge Base - http://tips.kbcafe.com/tips/

Quote:

> Hello All,

> I have a little problem that i hope some of you might be able to help me
> with.

> Basically i have a class which contains a function declared as static:

> // MyClass.h
> class CMyClass
> {
> public:
> // PUBLIC FUNCTIONS
>         static BOOL MyStaticFunction(void);
> // PUBLIC VARIABLES
>         BOOL m_bDone;
> };

> But the problem is i need to change the value of m_bDone in the function
> MyClass::MyStaticFunction(). Like this ...

> BOOL CMyClass::MyStaticFunction(void)
> {
>         m_bDone = FALSE;                // This generates a compiler error.
>         CMyClass::m_bDone = FALSE;      // This generates a compiler error.
> }

> If anyone knows a way around this problem, please get back to me either

> Thanks in advance,

> Conner.



Mon, 01 Jan 2001 03:00:00 GMT  
 static functions with non-static variables!
Hi,
By definition static member functions can access only static member
variables.

____\___________________________________
\___/Ljudmil Zahariev ( LZ )

Quote:

>Hello All,

>I have a little problem that i hope some of you might be able to help me
>with.

>Basically i have a class which contains a function declared as static:

>// MyClass.h
>class CMyClass
>{
>public:
>// PUBLIC FUNCTIONS
> static BOOL MyStaticFunction(void);
>// PUBLIC VARIABLES
> BOOL m_bDone;
>};

>But the problem is i need to change the value of m_bDone in the function
>MyClass::MyStaticFunction(). Like this ...

>BOOL CMyClass::MyStaticFunction(void)
>{
> m_bDone = FALSE; // This generates a compiler error.
> CMyClass::m_bDone = FALSE; // This generates a compiler error.
>}

>If anyone knows a way around this problem, please get back to me either

>Thanks in advance,

>Conner.



Mon, 01 Jan 2001 03:00:00 GMT  
 static functions with non-static variables!

Quote:

> Hi,
> By definition static member functions can access only static member
> variables.

> ____\___________________________________
> \___/Ljudmil Zahariev ( LZ )


That really isn't accurate.
Normal (non-static) members (including functions) are associated with a
particular instance of the class.
Static members (including functions) are not.

A static member function can access any member of the class (including
private members) but it must specify an instance of the class to access
a non-static member, just like a non-member function does.

Seth Jones



Mon, 01 Jan 2001 03:00:00 GMT  
 static functions with non-static variables!
Hi,

Yes I agree.
I only told the definition :-).

Quote:


>> Hi,
>> By definition static member functions can access only static member
>> variables.

>> ____\___________________________________
>> \___/Ljudmil Zahariev ( LZ )

>That really isn't accurate.
>Normal (non-static) members (including functions) are associated with a
>particular instance of the class.
>Static members (including functions) are not.

>A static member function can access any member of the class (including
>private members) but it must specify an instance of the class to access
>a non-static member, just like a non-member function does.

>Seth Jones



Tue, 02 Jan 2001 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. static functions and non static variables

2. One Problem in Calling Static function from Non static function

3. Accessing non-static functions from a static function

4. Pointers to non-static vs static functions

5. Static array containing non static objects and functions

6. Static and non-Static member - Signature

7. Creating a static class from non static Framework classes

8. static versus non static returnvalues

9. Linking Error - Static vs. Non-Static

10. Linking Static DLL vs Non Static DLL

11. Getting pointer to non-static member function from C callback function

12. Using Non-Static Callback Functions as member Functions VC5.0

 

 
Powered by phpBB® Forum Software