What is a Contiguous Object?

Hi,

I was asked this question in my school exam recently and didn't really understand it. I've googled 'contiguous object' but I don't find much related information.

Can you please explain the correct answer to this question or shed more light on it:

What is a contiguous object? Give a simple example of a contiguous object. If you have non-contiguous objects in your program, what three things should you explicitly implement? (Hint: one of these things is assignment operator "=" overloading)

Thanks!
There is no such term as contiguous object in C++.
However there is written that

An object of trivially copyable or standard-layout type (3.9) shall occupy contiguous bytes of storage.


And further

2 For any object (other than a base-class subobject) of trivially copyable type T, whether or not the object holds a valid value of type T, the underlying bytes (1.7) making up the object can be copied into an array of char or unsigned char.40 If the content of the array of char or unsigned char is copied back into the object, the object shall subsequently hold its original value.



Scalar types, trivially copyable class types (Clause 9), arrays of such types, and cv-qualified versions of these types (3.9.3) are collectively called trivially copyable types. Scalar types, trivial class types (Clause 9), arrays of such types and cv-qualified versions of these types (3.9.3) are collectively called trivial types. Scalar types, standard-layout class types (Clause 9), arrays of such types and cv-qualified versions of these types (3.9.3) are collectively called standard-layout types



6 A trivially copyable class is a class that:
— has no non-trivial copy constructors (12.8),
— has no non-trivial move constructors (12.8),
— has no non-trivial copy assignment operators (13.5.3, 12.8),
— has no non-trivial move assignment operators (13.5.3, 12.8), and
— has a trivial destructor (12.4).



Scalar types, standard-layout class types (Clause 9), arrays of such types and cv-qualified versions of these types (3.9.3) are collectively called standard-layout types.



7 A standard-layout class is a class that:
— has no non-static data members of type non-standard-layout class (or array of such types) or reference,
— has no virtual functions (10.3) and no virtual base classes (10.1),
— has the same access control (Clause 11) for all non-static data members,
— has no non-standard-layout base classes,
— either has no non-static data members in the most derived class and at most one base class with
non-static data members, or has no base classes with non-static data members, and
— has no base classes of the same type as the first non-static data member.108
Officialy, only trivially-copyable and standard-layout objects are required to occupy contiguous sequences of bytes, but they mention the rule of 3, and I would bet they call "non-contiguous" the objects that hold raw pointers to dynamically allocated objects.

Your best bet is to go with whatever definition your school provided.
Topic archived. No new replies allowed.