Global variable priority over local variable when global function called in scope of local variable c++

As soon as you call a free function, you are no longer inside the class. And you have lost the special this pointer. A (rather C-ish) way could be:

void FuncB(struct Foo* a) {   // expect a pointer to a Foo object
    a->FuncA();               // call the method on the passed object

struct Foo {
    void FuncA() {
        std::cout << "Hi";
    void FuncC() {
        FuncB(this);         // pass the special this pointer to the function

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top