Skip to content

Objects

  • Object
  • rvalue, lvalue
  • Reference
  • std::array

Which types and objects are present here? List them all.

#include <array>
struct Leg
{
int length;
};
struct Arm
{
int power;
};
struct Person
{
std::array<Leg, 2> legs;
Arm arms[2];
};
int main()
{
Person person;
}
Hint (object) 1 An object is a piece of memory of a particular type.
Hint (object) 2 An object can be of any type.
Hint (fields) 1

Recall the syntax for declaring fields in structures.

Hint (fields) 2

The syntax for declaring fields is similar to the syntax for declaring variables.

тип имя;
Hint (type) 1 A structure is a user-defined type.
Hint (type) 2

Types have names. A type name is not necessarily a single identifier (word); a type can have a more complex name.

For example, std::vector<int> is also a type name.

Hint (fields) 3

Field definitions are not objects.

Fields are objects only as part of an existing object. That object must have the user-defined type in which the field is declared.

Standard types (such as int) do not contain fields. Only user-defined types (structures) can declare fields.

Hint (array) 1 Arrays store several objects.
Hint (array) 2 C-style arrays are not objects in the ordinary sense of the word. They have peculiarities.
Answer

Objects:

person
person.legs
person.legs[0]
person.legs[1]
person.legs[0].length
person.legs[1].length
person.arms[0]
person.arms[1]
person.arms[0].power
person.arms[1].power

Types:

Person
Leg
Arm
int
std::array<Leg, 2>