Click Here

I thought after the function call of gen_aux before the loop, the static call on the type for r should have make it declared. but why not?

how static really works? this is what it's explained in the books:-

static type variable;

For local declarations, declares variable with static storage class. The value of variable persists across executions of this scope and is guaranteed to be initialized before the variable is used for the first time. When the program exits from the scope, the variable keeps its value until the next time the program enters that scope. We'll see in ยง13.4/244 that the meaning of static varies with context. 

Recommended Answers

All 2 Replies

    static methods can not access non-static class members because the static method has no idea what instance of the class the variable r belongs to.  

Making a local variable static means that it will remember its value between multiple calls of the same function. It does not mean that other function can access that function. A variable that is defined within one function can't be accessed from other functions (at least not directly - it's possible through pointers or references of course). Making the variable static doesn't change that.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.