If maxSize
is a normal member of class X then you can't access it that way. You would have to pass it as another parameter to the function.
If maxSize
is a static member of the class, then that code should work.
If this wasn't what you were asking, then you need to clarify your question and maybe add some more code showing what you're having trouble with.
Edit:
In your new example, the line you marked "illegal" would actually compile the way you've written it. (It's declaring a local X
pointer named myX
which only exists inside that function.)
But I'm guessing you actually meant:
int X::foo( const char * const key )
{
myX = NULL;
}
And that would fail because myX
is not a static variable. Static functions cannot access normal member variables. They can only access static variables.
You would need to revise your design:
- Either make
myX
a static member of X
if that is appropriate in your program.
- Or make
X::foo
a non-static member function.
- Or add another parameter to
X::foo
through which you can get access to myX
. There would be several ways depending how you want to design things. Here's an example: int X::foo( const char * const key, X *& theXpointer )