In a larger code base I have encountered code like this (see on godbolt):
struct Foo {};
struct Base {
Foo* a;
};
struct Bar : public Base {
static Foo* Bar::*mybar[];
};
Foo* Bar::Bar::*mybar[] = {
&Base::a
};
To be honest, I'm baffled. This looks like it's initializing a static array of Foo
pointers in Bar
with a non-static member variable of Base
. How is that even possible without an object?
(Disclaimer: This is found in production code that actually works - hopefully not relying on UB?)
Also, is there any problem if I remove the qualified name lookup like here? I'd like to refactor the code and make it more readable. All these Bar::
s seem quite superfluous, but since I'm not feeling so comfortable with the code I'd rather understand the implications first.