I've come across a peculiar case while designing my C++ object inheritance tree in a project. I expected the below to fail:
struct A {
protected:
struct C { };
};
struct B: A {
struct C { };
};
But, this compiles just fine. Is this like an override? I can see how this isn't ambiguous because they can be specified as A::C
and B::C
, but how does this act in polymorphic cases? Will it call the prescribed type's C or the instance's type's C? As in, suppose this code below works and func
exists in both implementations of C:
A x = B();
decltype(x)::C::func();
which C would have their function called? More generally, is their a resource that describes how code snippets like these resolve?