Reputation: 3658
class A {
int x;
};
class B : public A {
int y;
};
B b;
I know b
is considered a complete object of B
and the object that B
contains is a sub-object of A
.
But someone pointed me to this,
Paragraph 3, of C++ Standard 1.8
(1.8/3) For every object x, there is some object called the complete object of x, determined as follows: — If x is a complete object, then x is the complete object of x. — Otherwise, the complete object of x is the complete object of the (unique) object that contains x.
In this, I'm finding the wording the very confusing with all those x
s all over the place, Can you explain this with my example?
Upvotes: 1
Views: 799
Reputation: 477378
The quote is from the C++11 standard, 1.8. More completely:
2) Objects can contain other objects, called subobjects. A subobject can be a member subobject (9.2), a base class subobject (Clause 10), or an array element. An object that is not a subobject of any other object is called a complete object.
3) For every object x, there is some object called the complete object of x, determined as follows:
If
x
is a complete object, then x is the complete object ofx
.Otherwise, the complete object of x is the complete object of the (unique) object that contains
x
.
In other words, consider this:
struct A { }; struct B : A { };
A x[10];
B y;
Now x[1]
is an object whose complete object is x
, and y::A
is an object whose complete object is y
(and both subobjects are of type A
).
It's just terminology...
Upvotes: 3
Reputation: 73181
It sound to me that by "complete object" they are referring to the object that was returned by the new operator, or placed onto the stack as a local variable. For example, if we start with your code (above), b is the complete object for x. How did we get that? By working our way up the hierarchy:
(If b had instead been part of a still-larger object, then we would have had to go further up the hierarchy to find the complete object)
Upvotes: 3