Frage

I am working on a project and I am facing a little bit strange code which I cannot understand why and how can this happen !

I have a class Foo and Baz, and Foo has a non-static method that is called from Baz class without instantiating Foo:

class Foo {
    public:
       void qux(int a, int b);
};


class Baz {
    public:
        void bar(void);
};


void Baz::bar(void){
    Foo::qux(2,3);          // This should not happen as qux is not a static method !!
}
War es hilfreich?

Lösung

The only way that would work is if Baz was derived from Foo at some level.

Or, of course, Foo bears a different meaning in that scope (via a using, typedef, define or other).

If neither apply, your compiler is seriously broken.

Andere Tipps

This can happen in case of Baz is inherited from Foo.

In this case you can call method of the base class directly in the form that you mentioned:

void Baz::bar(void){
    Foo::qux(2,3);
}
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top