Objects
Concepts
Section titled “Concepts”- 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:
personperson.legsperson.legs[0]person.legs[1]person.legs[0].lengthperson.legs[1].lengthperson.arms[0]person.arms[1]person.arms[0].powerperson.arms[1].powerTypes:
PersonLegArmintstd::array<Leg, 2>