As we know, a direct or indirect base class's of a derived class public and protected members are available in that derived one.
So I have this example:
struct Foo{int x_ = 10;};
struct Bar : Foo{};
struct FooBar : Bar{
void f()const{
std::cout << &x_ << " : " << x_ << '\n';
std::cout << &Foo::x_ << " : " << Foo::x_ << '\n';
std::cout << &Bar::x_ << " : " << Bar::x_ << '\n';
std::cout << &FooBar::x_ << " : " << FooBar::x_ << '\n';
}
};
int main(){
FooBar fb{};
fb.f();
}
When I compile and run the program I get the output:
0x7ffc2f7ca878 : 10 1 : 10 1 : 10 1 : 10
So why accessing the address of the member data A::x_ through a fully-qualified names yields an "Invalid" address? but accessing it directly (unqualified lookup) is OK.
Is my program in Undefined Behavior?
I've compiled my program using GCC and CLANG.