1

A search in the C++ ISO draft 2020, Document Number 4849, for the term "member subobject" return 7 results. All of them are transcribed below;

(6.7.2 Object Model):

Objects can contain other objects, called subobjects. A subobject can be a member subobject (11.4), a base class subobject (11.7), or an array element. An object that is not a subobject of any other object is called a complete object. If an object is created in storage associated with a member subobject or array element e (which may or may not be within its lifetime), the created object is a subobject of e’s containing object if:...

(6.7.3 Lifetime)

[Note: 11.10.2 describes the lifetime of base and member subobjects. — end note]

(9.9 The using declaration)

[Note: Because a using-declarator designates a base class member (and not a member subobject or a member function of a base class subobject), a using-declarator cannot be used to resolve inherited member ambiguities

(11.4 Class Member)

[Note: A non-static data member of non-reference type is a member subobject of a class object (6.7.2). — end note]

(11.8 Member Name Lookup)

[Note: A static member, a nested type or an enumerator defined in a base class T can unambiguously be found even if an object has more than one base class subobject of type T. Two base class subobjects share the non-static member subobjects of their common virtual base classes. — end note]

(11.10.2 initializing bases and members)

Note: The declaration order is mandated to ensure that base and member subobjects are destroyed in the reverse order of initialization. — end note]

No one of them seems to be a definition of the term for me. The Class Member statement above says something interesting, but it doensn't say that "Only non-static data members of non referecente types are member subobjects". So What is member subobject?

  • 1
    _The Class Member statement above says something interesting_ But not really correct. NSDM is not a subobject, the same way as variable is not an object. Even thought there is an association between them in some circumstances. – Language Lawyer Oct 27 '21 at 17:00
  • Should I give up on this term? It looks too messy –  Oct 27 '21 at 17:06
  • 1
    I think the distinction @LanguageLawyer is making is that if you have a NSDM `int x` that is a "member" but not a "member subobject" – Cory Kramer Oct 27 '21 at 17:12
  • 2
    @CoryKramer Yes, NSDM is basically what can be declared or found by name lookup. `int x` in `struct S { int x; };` declares NSDM, `S::x` denotes (in the sense of lookup, not in the sense of [\[basic.lval\]/1](https://timsong-cpp.github.io/cppwp/n4868/basic.lval#def:glvalue)) NSDM etc. But there are no member subobjects here. Member subobject is a «thing» which can correspond to a NSDM in, say, class member access expression. `S{}.x` denotes (or designates, in [basic.lva]/1 sense) a member subobject of the temporary object created from `S{}` corresponding to `S::x` NSDM. – Language Lawyer Oct 27 '21 at 17:19
  • Can you show some C++ code where it is not clear whether something is a member subobject or not? – n. m. could be an AI Oct 28 '21 at 15:19

1 Answers1

0

Here is an example

struct A {
};

struct B {
    A a;
}

int main()
{
    A x;
    B y;
}

In this case x is a "complete object" of type A, whereas while y.a is also of type A it is a "member subobject" of the object y which is type B.

Cory Kramer
  • 114,268
  • 16
  • 167
  • 218
  • I was thinking something like this . But what would happen if the struct B were derived from A? It would exist a unnamed object of type A inside B that would be a base class subobject. So the `A a` would be a member subobject and the unnamed `A` not? –  Oct 27 '21 at 16:59