Can an object become a data member of a class without being declared in the member specification?

Viewed 93

C++ draft ISO quotes:

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:

  1. (2.1) — the lifetime of e’s containing object has begun and not ended, and
  2. (2.2) — the storage for the new object exactly overlays the storage location associated with e, and
  3. (2.3) — the new object is of the same type as e (ignoring cv-qualification)
struct A {};
struct B {A objectA;};
int main()
{   
    B b;
    A* point = new(&b.objectA) A();
} 

Based on the text and in the code above: this new created object becomes an subobject of b, a subobject is: a member subobject, a base class subobject or an array element. Obviously the new created is not an array element neither a base class subobject so I supose it must be a member subobject. So the new created object becomes a member of B ?

0 Answers
Related