c++name-lookup

How the process of member look up occurs in C++?


I'm using the document number 4901, C++ Draft ISO 2021, specifically 6.5.2 (Member Name Lookup). I'm failing in understanding a lot of uses of the terms "member subobject" and "base class subobjects". I already asked about these terms in : What is a member sub object? and What is a base class subobject

The Second question had an answer relatively satisfactory for me, the first one although didn't help me. I'm thinking that the explanation in the draft is a little too abstract, so I would rely on a rigorous defitnion of the terms cited above, but really didn't find any. Taking another path, How the member name look up occurs in practice? How the terms: member subobject and base class subobject are related to member names lookup?


Solution

  • From an ABI standpoint, there is very little distinction between B and C in the following:

    struct A {
      int x;
    };
    
    struct B : A {};
    
    struct C {
      A base;
    };
    

    Creating an object of type B or C both require creating an object of type A. In both cases, the instance of A belongs to the parent object. So in both cases they are sub-objects.

    For objects of type B, the A object is a base class sub-object.

    For objects of type C, the A object is a member sub-object.

    Edit: integrating stuff from followup questions in the comments.

    struct D : A {
      A base;
    };
    

    In D's case, there are 2 sub-objects of type A in each instance of D. One base class sub-object and one member sub-object.